Recently I have written a custom UITableViewCell
with a height of 60.0f. When it runs on different device, such as iPhone5
iPhone6
iPhone6 +
, the height and fontSize
changes automatically. How to fix the height?
- (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;
}
in the controller:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60.0;
}
将self.detailTextLabel.numberOfLines
设置为精确值,而不是0。这将关闭标签的自动大小调整。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.