2

ナビゲーションコントローラーをベースにしたアプリタブがあります。

ナビゲーション バーのタイトルは、タブのルート ページで問題なく表示されます。

しかし、別のView Controllerを上に押すと、このビューのタイトルを設定できません

これは、ルート ページとプッシュされたページに使用するコードです。

- (void)viewDidLoad
{
    [super viewDidLoad];    
UILabel *lava = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]autorelease];
    lava.backgroundColor = [UIColor clearColor];
lava.text = @"About us"; 

lava.textAlignment = UITextAlignmentCenter ;
lava.textColor = [UIColor whiteColor];
lava.font = [UIFont fontWithName:@"DroidSans-Bold" size:(46)];
lava.shadowColor = [UIColor blackColor];
lava.shadowOffset = CGSizeMake(2, 3);
self.navigationItem.titleView = lava;

 }

では、ナビゲーション バーにタイトルを設定するには何が欠けていますか?

ありがとう!

4

4 に答える 4

1
CGRect applicationFrame = CGRectMake(0, 0, 300, 40);
UIView * newView = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
[newView addSubview: lava];
self.navigationItem.titleView = newView;

このようにしてみてください。お役に立てればと思います。

于 2012-07-02T12:23:07.887 に答える
1

新しいコントローラ viewDidLoad でタイトルを変更する必要があります

于 2012-07-02T12:15:10.257 に答える
1

ビューコントローラーを一番上にプッシュするために何を使用していますか?

次の違いがあります。

[self.navigationController pushViewController:viewController animated:YES];

[self.navigationController presentModalViewController:viewController animated:YES];

したがって、presentModalViewController メソッドを使用している場合、タイトルは表示されません。

それが問題ではなく、pushViewController メソッドを使用している場合は、プッシュしているビュー コントローラーのタイトルを設定してみてください。

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"Controller title";
}
于 2012-07-02T12:29:59.767 に答える
1

あなたは試すことができますself.navigationController.navigationItem.titleView

または、iOS5以降を使用している場合..

UIImage *img=[UIImage imageNamed:@"NavBarBackground.png"];    
[self.navigationController.navigationBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];

NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:
                    [UIFont boldSystemFontOfSize:18.0f],UITextAttributeFont
                    ,[UIColor whiteColor],UITextAttributeTextColor
                    ,[UIColor blackColor],UITextAttributeTextShadowColor
                    ,[NSValue valueWithUIOffset:UIOffsetMake(0, 0)],UITextAttributeTextShadowOffset
                    , nil];
[self.navigationController.navigationBar setTitleTextAttributes:dict];

これviewDidLoadを rootViewController で一度呼び出すと、self.title=@"foo"どこでも使用できます。

于 2012-07-02T12:20:28.873 に答える