规范: Xcode 7.0.1,iOS用于构建9.0,8.4,设备iPhone
我正在处理UI_APPEARANCE_SELECTOR,并尝试在视图中设置颜色和字体的外观。视图是在customClass中为NavigationItem添加的,并有一个标题。我希望这个标题将是彩色的和样式的字体。导航项中的自定义子类在ViewControllers NavigationItem的童话板中设置。
这是我目前的状态: AppDelegate。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[[MySubtitleView appearance] setTitleLabelTextFont:[UIFont systemFontOfSize:14]];
[[MySubtitleView appearance] setTitleLabelTextColor:[UIColor whiteColor]];
...
}我的SubTitleView头
@import UIKit;
@interface MySubtitleView : UIView
@property (nonatomic) UILabel *titleLabel;
@property (nonatomic) UILabel *subtitleLabel;
@property UIColor *titleLabelTextColor UI_APPEARANCE_SELECTOR;
@property UIColor *subtitleLabelTextColor UI_APPEARANCE_SELECTOR;
@property UIFont *titleLabelTextFont UI_APPEARANCE_SELECTOR;
@property UIFont *subtitleLabelFont UI_APPEARANCE_SELECTOR;
@end在“类文件”中,我在向视图添加titleLabel时执行以下操作:
- (UILabel *)titleLabel
{
if (_titleLabel) {
return _titleLabel;
}
_titleLabel = [[UILabel alloc] init];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
_titleLabel.textColor = self.titleLabelTextColor;
_titleLabel.font = self.titleLabelTextFont;
return _titleLabel;
}当我运行我的应用程序,外观将不会被设置。我有一个黑色标题和一个黑色字幕。我不知道我做错了什么。
发布于 2015-09-30 08:38:09
我现在找到了解决方案:当加载MySubtitleView时,外观没有设置。它的设置后,视图加载,但然后什么都不会发生,因为我不关心这个。现在,我过了titleLabelTextColor的设置程序,并将颜色再次写入标签。在这里,外观将设置它,设置器将将其添加到textField中。
- (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor
{
_titleLabelTextColor = titleLabelTextColor;
self.titleLabel.textColor = titleLabelTextColor;
}编辑:,我认为这个问题很难,我找不到任何方法来解决它,所以我把这个答案标记为正确的答案,然后把它放进去。不同的想法:)
https://stackoverflow.com/questions/32860583
复制相似问题