2011-10-28 46 views

Trả lời

63

Đặt 's backBarButtonItemtintColor:

self.navigationItem.backBarButtonItem.tintColor = [UIColor redColor]; 

TIP: Nếu bạn muốn điều này được áp dụng cho tất cảUIBarButtonItem trường hợp trong ứng dụng của bạn theo mặc định, sau đó bạn có thể sử dụng API UIAppearance mới để thực hiện điều đó:

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]]; 
+0

tôi đã cố gắng this- (void) viewDidLoad { [ super viewDidLoad]; UIImageView * image = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "logobar.png"]]; NSLog (@ "Frame ==% f", image.frame.size.width); self.navigationItem.backBarButtonItem.tintColor = [UIColor redColor]; self.navigationItem.titleView = image; NSLog (@ "% f", self.navigationItem.titleView.frame.size.width); } nhưng không hoạt động –

+0

Phương pháp 2 đã hoạt động Cảm ơn –

+0

[[UIBarButtonMở xuất hiện] setTintColor: [UIColor redColor]]; Phương pháp này là hiện tại cho IOS 5.0 hoặc cao hơn làm thế nào để làm cho nó hoạt động cho các phiên bản thấp hơn? –

8

Dòng đầu tiên của câu trả lời của jacob không hoạt động đối với tôi vì backBarButtonItem là NULL. Nó là NULL vì nó được tạo ra sau này tự động khi chuyển sang một ViewController khác. Vào thời điểm đó, bạn có thể đặt tiêu đề của nút bằng

self.title = @"nice title"; // self is here the view(controller) within the popoverController 

nhưng bạn không thể đặt tông màu.

Điều gì làm việc cho tôi, là tạo UIBarButtonItem mới mà không có bất kỳ kiểu nào. Sau đó thiết lập các thuộc tính title và color và thiết lập nó như là backBarButtonItem.

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init]; 
backButton.title = @"go back - now!"; 
backButton.tintColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.7 alpha:1.0]; 
self.navigationItem.backBarButtonItem = backButton; 
[okButton release]; 
+0

Cảm ơn. Nó hoạt động hoàn hảo. – Philip007

3

Nếu bạn muốn chắc nút trông giống hệt như trong hình ảnh của bạn, bạn có thể sử dụng hình ảnh, quá:

ảnh
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"back_button_bg"] 
             forState:UIControlStateNormal 
             barMetrics:UIBarMetricsDefault]; 

Nền phải là một hình ảnh thay đổi kích thước cho kết quả tốt.

0

Cách tốt nhất tôi tìm thấy để thiết lập nó trên toàn cầu hoặc chỉ cục bộ là

[[UIBarItem appearance] setTitleTextAttributes: 
     [NSDictionary dictionaryWithObjectsAndKeys: 
     [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0], UITextAttributeTextColor, 
     [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor, 
     [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
     [UIFont fontWithName:@"AmericanTypewriter" size:0.0], UITextAttributeFont, 
     nil] 
     forState:UIControlStateNormal]; 
-1
[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]]; 

thử này Nó đang làm việc cho tôi ...

Các vấn đề liên quan