【发布时间】:2015-09-30 07:44:33
【问题描述】:
规格:Xcode 7.0.1、iOS 到 Build 9.0、8.4、iPhone 设备
我正在处理 UI_APPEARANCE_SELECTOR 并尝试设置视图中颜色和字体的外观。 View 被添加到 NavigationItem 的 customClass 中,并且有一个标题。我希望这个标题将被着色并使用字体设置样式。 Navigation Item 的 Custom 子类在 Storyboard 中为 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;
}
当我运行我的应用程序时,不会设置外观。我有一个黑色标题和一个黑色副标题。我不知道我做错了什么。
【问题讨论】:
标签: ios objective-c uiappearance