最近我写了一个高度为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;
}
答案 0 :(得分:0)
将self.detailTextLabel.numberOfLines
设置为精确值,而不是0.这将关闭标签的自动调整大小。