문제

I am trying to subclass and for some reason I'm having three issues.

The first is creating a transparent background. The Second is changing the textLabels font. The third is creating a border for the bottom in drawRect: (the green colour is just a tester)

Here is all my subclass' code:

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

It successfully logs a background view with the right image background colour and title. Also, the textLabel's colour changes too. But not the other two.

Does anyone know why?

Thanks

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top