图片的展示

来源:互联网 发布:qq飞车淘宝刷徒弟流程 编辑:程序博客网 时间:2024/04/30 20:41

图片分可点击和不可点击

可点击图片一般使用UIButton显示,不可点击一般使用UIImageView显示,
现在具体说说其中的一些属性和区别,
1,UIButton,
传说中的按钮,按钮显示图片分backgroundImage和image二中,
UIButton *pButton = [[UIButton alloc] init];
UIImage *pImage;
//设置按钮上的图片,图片按比例饿显示
[pButton setImage:pImage forState:UIControlStateNormal];
//设置按钮背景,图片会被拉伸充满整个button
[pButton setBackgroundImage:pImage forState:UIControlStateNormal];

2,UIImageView
UIImageView *pImageView = [[UIImageView alloc] init];
pImageView.image = pImage;
//设置图片的现实方式
pImageView.contentModel = UIViewContentModeScaleAspectFill;
//UIViewContentModeScaleToFill:铺满,图片可能被拉伸
//UIViewContentModeScaleAspectFit:适应显示,周边可能有空白出现
//UIViewContentModeScaleAspectFill:正常显示,图片可能超出范围

//超出部分不显示
pImageView.clipsToBounds = YES;
0 0
原创粉丝点击