我创建了一个自定义单元格,MatchCenterCell
,其中我创建了一个名为UILabel
priceLabel
,它坐落在一个UITableView
细胞内相对于图像的UILabel的位置。它目前设置的方法是像这样:如何设置在电池
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.PriceLabel = [[ UILabel alloc]initWithFrame:CGRectMake(90, 35, 70, 40)];
}
return self;
}
然而,这会导致问题,因为每个单元的图像大小有所不同,所以具有90 x坐标意味着有时会错位,如“最佳匹配“下面的标签显示:
我怎样才能使相对x坐标为cell.imageView
,使其排队的方式textLabel
和detailTextLabel
做上面呢?
使用自动布局。 – rdelmar 2014-11-14 22:20:58
@rdelmar说了什么。您可以直接向标签添加约束,以确保它与图像垂直和水平居中。 – brandonscript 2014-11-14 22:35:24