Imo*_*tep 8 fonts textcolor uitableview ios8
我有一个UITableViewHeaderFooterView,我在其中更改textLabel字体和背景颜色
UITableViewHeaderFooterView* header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"header"];
if(!header)
{
header = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"header"];
[header.textLabel setFont:[UIFont boldSystemFontOfSize:15]];
[header.contentView setBackgroundColor:[UIColor colorWithRed:213/255.0 green:213/255.0 blue:213/255.0 alpha:1]];
}
Run Code Online (Sandbox Code Playgroud)
以下是iOS 7的显示方式:

以下是iOS 8的显示方式:
setFont:似乎没有在这里生效,或者iOS 8上的iOS 8上的15pt字体更大
以下是我删除setFont:call时iOS 8的显示方式

如您所见,setFont对字体没有影响,但它在textColor上有效.
我错过了什么或者那些是"beta bug"(我使用的是来自XCode6 GM种子的模拟器,我在iOS 5 beta 5的iPhone 5上也有同样的问题)?
编辑: iOS 8版本和XCode 6.0.1似乎无法解决问题
Imo*_*tep -1
根据tubtub的回答,我做了一个 UITableViewHeaderFooterView 子类:
@interface CompatibilityTableViewHeaderFooterView : UITableViewHeaderFooterView
@property (nonatomic,readonly) UILabel* compabilityTextLabel;
@end
@implementation CompatibilityTableViewHeaderFooterView
{
UILabel* iOS8TextLabel;
NSLayoutConstraint* iOS8TextLabelLeftMarginConstraint;
}
-(instancetype) initWithReuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithReuseIdentifier:reuseIdentifier])
{
self.contentView.backgroundColor = GRIS_213;
self.compabilityTextLabel.font = [UIFont boldSystemFontOfSize:15];
}
return self;
}
-(UILabel*) compabilityTextLabel
{
if ([UIDevice currentDevice].systemVersion.floatValue < 8.0)
{
return self.textLabel;
}
else
{
if (!iOS8TextLabel)
{
iOS8TextLabel = [[UILabel alloc] init];
iOS8TextLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:iOS8TextLabel];
iOS8TextLabelLeftMarginConstraint = [NSLayoutConstraint constraintWithItem:iOS8TextLabel attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
[self addConstraint:iOS8TextLabelLeftMarginConstraint];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[iOS8TextLabel]-(>=0)-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(iOS8TextLabel)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[iOS8TextLabel]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(iOS8TextLabel)]];
}
return iOS8TextLabel;
}
}
-(UITableView*) searchForTableView
{
UIView* currentView = self;
while (currentView)
{
currentView = currentView.superview;
if ([currentView isKindOfClass:[UITableView class]])
{
return (UITableView*)currentView;
}
}
return nil;
}
-(void) layoutSubviews
{
[super layoutSubviews];
UITableView* tableView = [self searchForTableView];
if (tableView)
{
iOS8TextLabelLeftMarginConstraint.constant = tableView.separatorInset.left;
}
}
Run Code Online (Sandbox Code Playgroud)
所以基本上我现在只使用该compabilityTextLabel属性而不是textLabel. 请注意,左侧空间约束会自动更新以匹配 tableView 分隔符插入。请随意评论/改进我的代码;)
| 归档时间: |
|
| 查看次数: |
4867 次 |
| 最近记录: |