cell添加选中时的背景图片、显示图片和图片自适应框的大小

本文介绍如何在iOS开发中为UITableViewCell设置选中状态的背景图片,展示特定图片并实现图片自适应框大小的方法。通过代码示例,详细解释了如何利用UIKit框架中的UIImageView和UIView组件来实现这些功能。

1.给cell添加选中时的背景图片

UIView *myview = [[UIView alloc] init];

myview.frame = CGRectMake(0, 0, 320, 47);

myview.backgroundColor =

[UIColor colorWithPatternImage:[UIImage

imageNamed:@"0006.png"]];

cell.selectedBackgroundView = myview;

2.显示图片

CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f,

109.0f);

UIImageView *myImage = [[UIImageView alloc]

initWithFrame:myImageRect];

[myImage setImage:[UIImage

imageNamed:@"myImage.png"]];

myImage.opaque =YES;

[self.view addSubview:myImage];

3.图片自适应框的大小

NSString*imagePath = [[NSBundle mainBundle]

pathForResource:@"XcodeCrash"ofType:@"png"];

UIImage *image = [[UIImage

alloc]initWithContentsOfFile:imagePath];

UIImage *newImage= [image transformWidth:80.f height:

240.f];

UIImageView *imageView = [[UIImageView

alloc]initWithImage:newImage];

[self.view addSubview:imageView];

转载于:https://www.cnblogs.com/CJH5209/p/6072132.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值