【发布时间】:2015-05-22 08:48:33
【问题描述】:
最近我写了一个自定义的UITableViewCell,高度为60.0f。当它在不同的设备上运行时,例如iPhone5iPhone6iPhone6 +,高度和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;
}
【问题讨论】:
-
请显示tableview创建代码,可能你需要将UITableView的rowHeight改为60.0f而不是UITableViewAutomaticDimension
-
对不起,这里是创作:
-
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 60.0; }
标签: ios uitableview autolayout font-size fixed