在我的自定义单元格中,我想居中图像,但这不起作用。
self.leftImage = [[[UIImageView alloc] initWithImage:cry] autorelease] ;
float h=cell.frame.size.height;
float w=cell.frame.size.width;
CGRect r = leftImage.frame;
r.origin = cell.frame.origin;
r.origin.x = w/ 2 - r.size.width / 2;
r.origin.y = h / 2 - r.size.height / 2 + 12;
leftImage.frame = r;
[self.contentView addSubview:leftImage];
最佳答案
我认为您尝试在创建新单元格时在- (UITableViewCell *)tableView:(UITableView *)tableViewRef cellForRowAtIndexPath:(NSIndexPath *)indexPath
中执行此操作,或者在init节中尝试在单元格本身中执行此操作。目前,单元格没有正确的框架,您不能依靠它。
关于iphone - 如何在自定义单元格中居中放置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6979767/