子类化UITableViewHeaderFooterView - 半透明背景和字体

时间:2013-06-26 17:15:42

标签: uitableview sectionheader

我正在尝试子类化,出于某种原因,我遇到了三个问题。

第一个是创建透明背景。 第二个是更改textLabel s字体。 第三个是在drawRect:中为底部创建边框(绿色只是测试人员)

这是我所有的子类'代码:

+ (EVSectionHeaderView *)sectionHeaderViewWithSectionHeaderViewStyle:(SectionHeaderViewStyle)sectionHeaderViewStyle title:(NSString *)title
{
    EVSectionHeaderView *sectionHeaderView = [[EVSectionHeaderView alloc] init];

    UIView *backgroundView = [[UIView alloc] initWithFrame:sectionHeaderView.frame];
    [sectionHeaderView setBackgroundView:backgroundView];

    switch (sectionHeaderViewStyle) {
        case SectionHeaderViewStylePaper:
            [sectionHeaderView.backgroundView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Paper Texture"]]];
            break;

        default:
            break;
    }

    [sectionHeaderView.layer setOpacity:0.1f];

    [sectionHeaderView.textLabel setText:title];
    [sectionHeaderView.textLabel setFont:[UIFont fontWithName:@"AvenirNextCondensed-DemiBold" size:14.0f]];
    [sectionHeaderView.textLabel setTextColor:[UIColor darkGrayColor]];

    NSLog(@"Section background: %@", sectionHeaderView.backgroundView);

    return sectionHeaderView;
}

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];

    CGContextRef context = UIGraphicsGetCurrentContext();

    //  Bottom border
    //
    CGContextSetFillColorWithColor(context, [[UIColor greenColor] colorWithAlphaComponent:0.12f].CGColor);
    CGContextFillRect(context, CGRectMake(0.0f, CGRectGetHeight(self.contentView.frame) - 1.0f, CGRectGetWidth(self.contentView.frame), 1.0f));
}

它成功记录了具有正确图像背景颜色和标题的背景视图。此外,textLabel的颜色也会发生变化。但不是其他两个。

有谁知道为什么?

由于

0 个答案:

没有答案