本日はcocos2dではなくObjectiv-C。
(くくり的にはObjective-C>cocos2dなんでしょうけど)
昨日より、StoryBoardを使って画面遷移を実装しているのですが
StoryBoardにつけたUINavigationBarのtitleの変更方法がわからない
StoryBoard上で変更するのではなく、入ってきた値によって
動的にタイトルを決めたいのに、、、うまくいかない。
まずためしたのが
NavigationBar.title
なんてそもそも存在しない。
self.title
かわらない
意味がわからない
ググったら
[[NavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
でタイトルとかフォントとか設定できるかもって、、、
1 2 3 4 5 |
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont boldSystemFontOfSize:20.0], UITextAttributeFont, [UIColor whiteColor], UITextAttributeTextColor, [UIColor clearColor], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],UITextAttributeTextShadowOffset, nil]; |
タイトルの文字列変えるところないじゃないか?
(これはもう少し調べたらでてくるかもしれないですが)
さらにさらにぐぐっていったら
Navbar のタイトルをプログラム的に変更します。
ありました。
1 2 3 4 5 6 7 |
//.h UINavigationBar *NavigationBar; @property (retain, nonatomic) IBOutlet UINavigationBar *NavigationBar; //.m @synthesize NavigationBar; NavigationBar.topItem.title = @"dekita!!"; |
こういうのって公式とかにいけば資料に書いてあるんですかね?
しんどかったです。
[…] ■【UINavigationBarとかとか】アプリ開発日記(6/6) |さんぼんばしら -ガッツリ開発のお話。 […]
UINavigationController が保持している UIViewController の title プロパティをセットすればそれがタイトルに表示されるはずです。
自分はこれをどこで知ったのか忘れましたが、UINavigationController のクラスリファレンスに書いてありました。
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
* Updating the Navigation Bar
– If no custom title view is set, the navigation bar displays a label containing the view controller’s default title. The string for this label is usually obtained from the title property of the view controller itself. If you want to display a different title than the one associated with the view controller, set the title property of the view controller’s navigation item instead.
ありがとうございます!やってみますし
ちゃんとリファレンス読みます