Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 更改TitleTextAttributes文本颜色取决于导航栏颜色_Ios_Uinavigationbar - Fatal编程技术网

Ios 更改TitleTextAttributes文本颜色取决于导航栏颜色

Ios 更改TitleTextAttributes文本颜色取决于导航栏颜色,ios,uinavigationbar,Ios,Uinavigationbar,我有两个不同导航栏颜色的控制器。假设我想用导航栏黑色和TitleTextAttributes颜色白色设置第一个控制器,在导航到第二个控制器后,它会更改导航栏白色和TitleTextAttributes黑色。导航栏颜色更改,但标题文本属性未更改。请建议 我写了这段代码并用在viewwillappearch方法中 内部导航栏类别 typedef NS_ENUM( NSUInteger, UINavigationBarColor) { White, Black }; +(void)s

我有两个不同导航栏颜色的控制器。假设我想用导航栏黑色和TitleTextAttributes颜色白色设置第一个控制器,在导航到第二个控制器后,它会更改导航栏白色和TitleTextAttributes黑色。导航栏颜色更改,但标题文本属性未更改。请建议

我写了这段代码并用在viewwillappearch方法中

内部导航栏类别

typedef NS_ENUM( NSUInteger, UINavigationBarColor) {
    White,
    Black
};

+(void)setNavigationColor:(UINavigationBarColor)color{
    if (color == White) {
         [[self appearance] setTintColor:[UIColor whiteColor]];
        NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor blackColor]};
        [[self appearance] setTitleTextAttributes:attributes];
    } else {
        [[self appearance] setTintColor:[UIColor blackColor]];
        NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
        [[self appearance] setTitleTextAttributes:attributes];
    }
}

您的代码正在设置
UINavgiationBar外观上的
tintColor
titleTextAttributes
。这仅影响新创建的导航栏。它不会更改任何现有的导航栏


您需要将
setNavigationColor
设置为实例方法,并将
[self-appearance]
更改为仅
self

错误,对于选择器“setTitleTextAttributes:”没有已知的类方法,正如我所说的,将其更改为实例方法(
+
->
-
)。