方式一:
UIImageView *imageView = UIImageView.new;
imageView.image = [UIImage imageNamed:@"1"];
//CGRectMake方法
imageView.frame = CGRectMake(100,100,200,400);
//强制类型转换
imageView.frame = (CGRect){{100,100},{200,400}};
方式二:
UIImageView *imageView = UIImageView.new;
UIImage *image = [UIImage imageNamed:@"1"];
imageView.frame = CGRectMake(100,10, image.size.width, image.size.height);
//设置图片
imageView.image = image;
方式三:
UIImage *image = [UIImage imageNamed:@"1"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100,10, image
.size.width, image.size.height)];
方式四:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithNamed:@"1"]];
//改变位置
imageView.center = CGPointMake(self.view.frame.size.width*0.5, self.view.frame.size.height*0.5);
网友评论