这里改变字体大小的问题,故障与UITableViewHeaderFooterView
我子类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;
}
颜色的东西工作正常,但字体没” T改变,所以我日志出队:
- (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。 – DevGansta