这是问题,
我分类一个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子类的layoutSubviews方法中的字体,它将适用.
- - (void)layoutSubviews {
- [super layoutSubviews];
- // Font
- self.textLabel.font = [UIFont systemFontOfSize:20];
- }