0

以下のコードを使用して、すべてのビューのナビゲーションバーを変更しています。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

UIImage *gradientImage44 = [[UIImage imageNamed:@"clear_navigation_bar_texture_44"]
                            resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:gradientImage44 forBarMetrics:UIBarMetricsDefault];
}

しかし、ナビゲーションバーを、ユーザーがアプリの「テーマ」に基づいて選択した別の画像に変更できるようにしたいと思います。問題は、アプリが読み込まれたときにのみ機能するため、ここにそのコードを入れることができないことです。そこで、コードを別のメソッドにして、didFinishLaunching...メソッドとユーザーが「テーマ」を変更したときに呼び出すviewControllerメソッドで呼び出すことを考えました。私の質問は、これをどのように行うのか、それとももっと良い方法があるのか​​ということです。

ありがとう!

4

2 に答える 2

2

You don't have to set the theme in the app delegate; you can do it anywhere you want (and you can even make it interactive). The only thing you need to be aware of is that attributes set via UIAppearance will only be instantiated with new views. If you have existing views that need updating, you need to do that manually. For example:

UIImage *gradientImage44 = [[UIImage imageNamed:@"clear_navigation_bar_texture_44"] resizableImageWithCapInsets:UIEdgeInsetsZero];
[[UINavigationBar appearance] setBackgroundImage:gradientImage44 forBarMetrics:UIBarMetricsDefault];
[[self navigationController] navigationBar] setBackgroundImage:gradientImage44 forBarMetrics:UIBarMetricsDefault];
于 2013-02-16T04:38:10.913 に答える
0

Settings.app のテーマを変更していますか? アプリのデリゲートにテーマコードを入れるだけ-applicationWillEnterForeground:です...

于 2013-02-16T04:22:28.680 に答える