我試圖居中UIImageView的寬度方向的一個UITableViewCell用下面的代碼:如何將UIImageView放置在UITableViewCell中,而不管方向如何?
// 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];
我試圖居中的UIImageView在UITableCellView不管iPad或iPhone設備處於什麼方位有誰知道正確的方法來做到這一點?
我選擇了'backcover_imageview.center = CGPointMake(cell.contentView.bounds.size.width/2,backcover_imageview.center.y);'爲我工作。感謝您的建議! – 2011-06-17 18:13:27