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

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



