ableViewHeaderFooterView中更改字体大小的

ableViewHeaderFooterView中更改字体大小的

本文介绍了在UITableViewHeaderFooterView中更改字体大小的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题,

我将UITableViewHeaderFooterView子类化并希望更改字体大小:

I subclass a UITableViewHeaderFooterView and want to change the font size:

- (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;
}

颜色的东西工作正常,但字体没有变化,所以我log dequeue:

The color stuff works fine, but the font didn't change, so I log the dequeue:

- (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

The font still goes right in here, so I log in didLayoutsubviews:

-(void)viewDidLayoutSubviews
{
    UITableViewHeaderFooterView *head = [self.tableView headerViewForSection:0];
    NSLog(@"ccc%@", head.textLabel.font);
}

并且字体大小神奇地恢复到默认值!!!但我之间没有做任何事情,如果我在 viewDidLayoutSubviews 中再次更改字体大小,则字体变为正确。

and the font size is magically CHANGED back to the default!!! But I didn't do anything between there, and If I change the font size again in viewDidLayoutSubviews, the font becomes right.

它让我疯狂!

当子类化单元格时,我做同样的字体更改,它工作正常!所以有人能告诉我发生了什么事吗?谢谢!

And I do the same font changing when subclass the cell, and it works fine! so can anyone tell me what's going on? Thanks!

这是日志:

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 方法中的字体将适用。

It doesn't seem like the right place to put it, but you can change the font in the layoutSubviews method of your UITableViewHeaderFooterView subclass and it will apply properly.

- (void)layoutSubviews {
    [super layoutSubviews];

    // Font
    self.textLabel.font = [UIFont systemFontOfSize:20];
}

这篇关于在UITableViewHeaderFooterView中更改字体大小的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 01:27