【发布时间】:2014-02-09 08:07:25
【问题描述】:
问题来了,
我继承了一个 UITableViewHeaderFooterView 并想更改字体大小:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.textLabel.textColor = [UIColor colorWithWhite:0.8 alpha:1.0];
//the font is not working
self.textLabel.font = [UIFont systemFontOfSize:20];
NSLog(@"aaa%@", self.textLabel.font);
}
return self;
}
颜色工作正常,但字体没有改变,所以我记录了出队:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UITableViewHeader *headerView = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:MWDrawerHeaderReuseIdentifier];
headerView.textLabel.text = self.sectionTitles[@(section)];
NSLog(@"bbb%@", headerView.textLabel.font);
return headerView;
}
字体还在这里,所以我登录didLayoutsubviews:
-(void)viewDidLayoutSubviews
{
UITableViewHeaderFooterView *head = [self.tableView headerViewForSection:0];
NSLog(@"ccc%@", head.textLabel.font);
}
字体大小神奇地变回了默认值!!!但是我没有在这之间做任何事情,如果我在viewDidLayoutSubviews 中再次更改字体大小,字体就会正确。
它让我发疯!!!
当子类化单元格时,我会更改相同的字体,而且效果很好!所以谁能告诉我发生了什么事?谢谢!
这是日志:
2014-02-09 16:02:03.339 InternWell[33359:70b] aaa<UICTFont: 0x8da4290> font-family: ".HelveticaNeueInterface-M3"; font-weight: normal; font-style: normal; font-size: 20.00pt
2014-02-09 16:02:03.339 InternWell[33359:70b] bbb<UICTFont: 0x8da4290> font-family: ".HelveticaNeueInterface-M3"; font-weight: normal; font-style: normal; font-size: 20.00pt
2014-02-09 16:02:03.341 InternWell[33359:70b] aaa<UICTFont: 0x8da4290> font-family: ".HelveticaNeueInterface-M3"; font-weight: normal; font-style: normal; font-size: 20.00pt
2014-02-09 16:02:03.342 InternWell[33359:70b] bbb<UICTFont: 0x8da4290> font-family: ".HelveticaNeueInterface-M3"; font-weight: normal; font-style: normal; font-size: 20.00pt
2014-02-09 16:02:03.343 InternWell[33359:70b] ccc<UICTFont: 0x8d22650> font-family: ".HelveticaNeueInterface-MediumP4"; font-weight: bold; font-style: normal; font-size: 14.00pt
2014-02-09 16:02:03.343 InternWell[33359:70b] ccc<UICTFont: 0x8d22650> font-family: ".HelveticaNeueInterface-MediumP4"; font-weight: bold; font-style: normal; font-size: 14.00pt
【问题讨论】:
-
即使没有子类化 UITableViewHeaderFooterView 也会出现同样的问题,设置的字体会在视图呈现时重置。在 iOS 9.3 上检查。
标签: ios uitableview