2
[[[UINavigationBar appearance] setTitleView:button]

上記のコード行を使用して、すべてのナビゲーション アイテムのボタンとしてタイトル ビューを設定しようとしましたが、機能しません。

4

5 に答える 5

6

ナビゲーション バーの外観のカスタマイズ

barStyle、tintColor、および半透明のプロパティを変更しても問題ありませんが、frame、bounds、alpha、または hidden プロパティなどの UIView レベルのプロパティを直接変更してはなりません。

詳細については、apple doc UINavigationBar クラス リファレンスを参照してください。

編集 ->

私はあなたの質問を解決しました

[[UINavigationBar appearance] addSubview:yourView];  

その他のナビゲーション関連クエリ

于 2012-12-15T07:36:30.490 に答える
0

この男を試してみてください...

//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];

それが機能しているかどうかを教えてください!!!!

ハッピーコーディング!!!

于 2012-12-15T06:53:15.290 に答える
0

これは、addDelegate でナビゲーション コントローラーを作成し、タイトルを設定する方法です。次のコードを didFinishLaunchingWithOptions メソッドに追加する必要があります。viewController のルート ビューを設定する必要があることに注意してください。これは、viewController で、navigationController 内に表示されます。

  yourViewController *mainVC = [[yourViewController alloc]init];
  UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:mainVC];
  navigationController1.title = @"title";
[window addSubview:navigationController1.view];
于 2012-12-15T06:53:47.217 に答える
0

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];
    }
} 

私は実装していないので、これは正しいと思います。

于 2012-12-15T07:36:28.193 に答える