2012-01-17 3 views
2

私はUINavigationControllerアプリケーションを作成しました。 UILavelをUINavigationBarに追加しましたが、問題があります。 UINavigationBarが左または右に移動しているとき、私のラベルは動いていません。どのように問題を解決するのですか?UINavigationBar:移動効果のあるUILabelを追加

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(70, 0, 200, 44)] autorelease]; 
label.text = @"There are too car on the ..."; 
label.backgroundColor = [UIColor clearColor]; 
[self.navigationController.navigationBar addSubview:label]; 

答えて

3

ここでの問題は、ラベルをUINavigationBarに直接設定することです。カスタマイズされたラベルが不要で、デフォルトの動作で十分なら、代わりにUIViewControllerタイトルプロパティを設定する必要があります。ただし、カスタマイズされたラベルが必要な場合は、UIViewControllerのnavigationItem titleViewプロパティを設定する必要があります。下記の例をご覧ください。私はと考えていますはアクティブビューコントローラです:

// for a simple title, just set the view controllers title property 
[self setTitle:@"There are too car on the ..."; 

// for a custom label, you need to set navigationItem.title property 
UILabel *label = [[[UILabel alloc] init] autorelease]; 
label.text = @"There are too car on the ..."; 
label.textColor = [UIColor yellowColor]; 
label.backgroundColor = [UIColor redColor]; 
[self.navigationItem setTitleView:label]; 
関連する問題