這裏改變字體大小的問題,故障與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