Subclassing UITableViewHeaderFooterView - semi-transparent background and font
-
01-06-2022 - |
题
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 textLabel
s 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
没有正确的解决方案
不隶属于 StackOverflow