[[[UINavigationBar appearance] setTitleView:button]
上記のコード行を使用して、すべてのナビゲーション アイテムのボタンとしてタイトル ビューを設定しようとしましたが、機能しません。
[[[UINavigationBar appearance] setTitleView:button]
上記のコード行を使用して、すべてのナビゲーション アイテムのボタンとしてタイトル ビューを設定しようとしましたが、機能しません。
ナビゲーション バーの外観のカスタマイズ
barStyle、tintColor、および半透明のプロパティを変更しても問題ありませんが、frame、bounds、alpha、または hidden プロパティなどの UIView レベルのプロパティを直接変更してはなりません。
詳細については、apple doc UINavigationBar クラス リファレンスを参照してください。
編集 ->
私はあなたの質問を解決しました
[[UINavigationBar appearance] addSubview:yourView];
その他のナビゲーション関連クエリ
この男を試してみてください...
//put whatever object in this view..for example button that you want to put...
UIView* ctrl = [[UIView alloc] initWithFrame:navController.navigationBar.bounds];
ctrl.backgroundColor = [UIColor yellowColor];
ctrl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[navController.navigationBar addSubview:ctrl];
それが機能しているかどうかを教えてください!!!!
ハッピーコーディング!!!
これは、addDelegate でナビゲーション コントローラーを作成し、タイトルを設定する方法です。次のコードを didFinishLaunchingWithOptions メソッドに追加する必要があります。viewController のルート ビューを設定する必要があることに注意してください。これは、viewController で、navigationController 内に表示されます。
yourViewController *mainVC = [[yourViewController alloc]init];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:mainVC];
navigationController1.title = @"title";
[window addSubview:navigationController1.view];
iOS4 を使用している場合は、drawRect をオーバーライドできます
@implementation UINavigationBar (UINavigationBarCategory)
-(void)drawRect:(CGRect)rect
{
UIImageView *itleImageView = //create object
[self addSubView:titleImageView];
//set title view in navigation bar
}
@end
iOS 5、
if ([[UIDevice currentDevice].systemVersion floatValue] >= 5.0) {
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
UIImageView *itleImageView = //create object
[self.navigationController.navigationBar addSubView:titleImageView];
}
}
私は実装していないので、これは正しいと思います。