Alb*_*eal 7 iphone uitableview uiimageview ipad ios
我正在尝试使用以下代码在UITableViewCell中以宽度方式居中UIImageView:
// self.cover_image is a UIImage variable
// cell is a UITableCellView
UIImageView* backcover_imageview = [[[UIImageView alloc] initWithImage:self.cover_image] autorelease];
[backcover_imageview sizeToFit];
//center image
//float xPos = cell.contentView.frame.size.width - (self.cover_image.size.width/2);
//TODO: need better solution
//Eyeballing attempt:
float xPos = self.cover_image.size.width - 25;
CGRect bookcover_frame = backcover_imageview.frame;
bookcover_frame.origin.x = xPos;
backcover_imageview.frame = bookcover_frame;
backcover_imageview.tag = 9000;
backcover_imageview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[cell.contentView addSubview:backcover_imageview];
Run Code Online (Sandbox Code Playgroud)
我试图将UIImageView置于UITableCellView的中心,无论iPad或iPhone设备的方向如何.有谁知道正确的方法吗?
wzb*_*zon 12
我添加了两个autoresizing mask并使用你的代码和PengOne的答案得到了一个很好的结果:
playImage.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
[cell.contentView addSubview:playImage];
playImage.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2);
Run Code Online (Sandbox Code Playgroud)
添加backcover_imageView
到contentView
单元格后,使用它来居中它:
imageView.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13483 次 |
最近记录: |