首页 > 代码库 > cell添加选中时的背景图片、显示图片和图片自适应框的大小

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

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];

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