Snail—UI学习之UIImage及UIImageView
2015-07-22 20:59
597 查看
图片是贴在ImageView上面的
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
[self createButton];
[self createImage];
}
- (void)createImage{
//加载本地图片的两种方式
//1、通过图片路径获取
//先获取图片的路径
NSString * path = [[NSBundle mainBundle] pathForResource:@"star_icon@2x" ofType:@"png"];
//通过路径创建一个图片
UIImage * image1 = [[UIImage alloc] initWithContentsOfFile:path];
//生成一个UIImageView 把照片放在view上
UIImageView * firstImageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 31, 30)];
//把图片方到view上面
firstImageView.image = image1;
[self.view addSubview:firstImageView];
//2、通过图片的名字加载图片
UIImageView * secondImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"star_icon@2x.png"]];
secondImageView.frame = CGRectMake(100, 100, 31, 30);
[self.view addSubview:secondImageView];
//从网络上加载图片
NSString * urlPath = @"https://www.baidu.com/img/bd_logo1.png";
NSURL * url = [NSURL URLWithString:urlPath];
UIImageView * thirdImageView = [[UIImageView alloc] initWithFrame:CGRectMake(40, 40, 150, 80)];
[thirdImageView setImageWithURL:url];
[self.view addSubview:secondImageView];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
[self createButton];
[self createImage];
}
- (void)createImage{
//加载本地图片的两种方式
//1、通过图片路径获取
//先获取图片的路径
NSString * path = [[NSBundle mainBundle] pathForResource:@"star_icon@2x" ofType:@"png"];
//通过路径创建一个图片
UIImage * image1 = [[UIImage alloc] initWithContentsOfFile:path];
//生成一个UIImageView 把照片放在view上
UIImageView * firstImageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 31, 30)];
//把图片方到view上面
firstImageView.image = image1;
[self.view addSubview:firstImageView];
//2、通过图片的名字加载图片
UIImageView * secondImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"star_icon@2x.png"]];
secondImageView.frame = CGRectMake(100, 100, 31, 30);
[self.view addSubview:secondImageView];
//从网络上加载图片
NSString * urlPath = @"https://www.baidu.com/img/bd_logo1.png";
NSURL * url = [NSURL URLWithString:urlPath];
UIImageView * thirdImageView = [[UIImageView alloc] initWithFrame:CGRectMake(40, 40, 150, 80)];
[thirdImageView setImageWithURL:url];
[self.view addSubview:secondImageView];
}
相关文章推荐
- POJ Blue Jeans 3080【KMP+string】
- hdu 5297 Y sequence 容斥+迭代
- [leedcode 115] Distinct Subsequences
- 第一次写博客,为自己学习apue的每一步做好记录
- [翻译] M13ProgressSuite
- break label和continue label
- [Leetcode]-Unique Paths II
- Message Queue基本使用说明
- 多校第一场 1010 hdu 5297 Y sequence(容斥+二分)
- Snail—UI学习之UIButton实现界面跳转及属性传值
- Snail—UI学习之得到某组件的方法
- HDU 5288 OO’s Sequence(数学啊 多校2015)
- [Leetcode]-Unique Paths
- 每天一个小知识点10(jQuerMobile总结一)
- OO’s Sequence
- 仿JD商城UI布局达到90%
- HDU5288.OO’s Sequence(多校第一题)
- 1151 - Buy or Build
- hdu 5288 OO’s Sequence(15多校第一场1001)
- Snail—UI学习之UIButton