![](/img/trans.png)
[英]How to fix tableview cell and textview height dynamically using autolayouts
[英]how to fix the height of a tableview cell
最近,我編寫了一個高度為60.0f的自定義UITableViewCell
。 當它在其他設備(例如iPhone5
iPhone6
iPhone6 +
,高度和fontSize
會自動更改。 如何確定高度?
- (id)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (!self) {
return nil;
}
self.textLabel.adjustsFontSizeToFitWidth = NO;
self.textLabel.font = [UIFont systemFontOfSize:15.0f];
self.detailTextLabel.adjustsFontSizeToFitWidth = NO;
self.detailTextLabel.font = [UIFont systemFontOfSize:12.0f];
self.detailTextLabel.numberOfLines = 0;
_switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(250, 9, 30, 20)];
_switchButton.tag = 400;
[_switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_switchButton];
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.frame = CGRectMake(250, 9, 60, 30);
[_button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_button];
_button.backgroundColor = [UIColor clearColor];
return self;
}
在控制器中:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60.0;
}
將self.detailTextLabel.numberOfLines
設置為精確值,而不是0。這將關閉標簽的自動大小調整。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.