【问题标题】:UI_APPEARANCE_SELECTOR is not workingUI_APPEARANCE_SELECTOR 不工作
【发布时间】: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


    【解决方案1】:

    我现在找到了解决方案: 加载 MySubtitleView 时,未设置外观。它是在视图加载后设置的,但是什么都不会发生,因为我不在乎。现在我覆盖了 titleLabelTextColor 的设置器并将颜色再次写入标签。这里外观会设置它,setter 会将它添加到 textField

    - (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor
    {
        _titleLabelTextColor = titleLabelTextColor;
        self.titleLabel.textColor = titleLabelTextColor;
    }
    

    编辑: 我认为这个问题很难,我找不到任何可以解决的问题,所以我将此答案标记为正确答案并让它进入。思考不同:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      • 2019-01-19
      • 1970-01-01
      • 2018-12-22
      • 2016-04-19
      相关资源
      最近更新 更多