UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 50, 50)];
imageview.backgroundColor=[UIColor blueColor];
[self.view addSubview:imageview];
UIImage *image=[UIImage imageNamed:@"图片名"];
imageview.image=image;
其中图片名如果是png图片则不用写扩展名,否则需要加上扩展名。
本文介绍如何使用Objective-C为UIImageView设置背景颜色及图片。通过代码创建UIImageView,并将其添加到视图中,随后设置背景图片,特别指出加载图片时是否需要添加扩展名。
1286

被折叠的 条评论
为什么被折叠?



