2012-12-03 43 views
10

मैं UIBarButtonItem's रंग को हरे रंग में कैसे सेट कर सकता हूं? मैं आईओएस 4 का उपयोग कर रहा हूं, कोई टिंट संपत्ति नहीं है। क्रिप्या मेरि सहायता करे।बदलें UIBarbuttonItems रंग

+0

आप मेरा उत्तर की कोशिश की? कृपया मुझे बताएं कि क्या आपको अभी भी समस्याएं हैं। –

+0

@ मिधुनम: यूआईबारबटन का रंग बदल गया। लेकिन शीर्षक और कार्रवाई कैसे सेट कर सकते हैं? – user1871678

+0

मैंने अपना जवाब संपादित कर लिया है, कृपया जांचें कि यह काम कर रहा है या नहीं। –

उत्तर

14

आईओएस 4 में:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
[button setBackgroundImage:[UIImage imageNamed:@"green.png"] forState:UIControlStateNormal]; 
button.frame=CGRectMake(0.0, 100.0, 60.0, 30.0); 
[button setTitle:@"Green" forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(yourAction) forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithCustomView:button]; 

यहाँ आप ऐसा करने के लिए एक हरे रंग की छवि की जरूरत है, तो आप इस छवि के साथ एक कस्टम बटन बनाने और UIBarButtonItem को देखते के रूप में सेट कर रहे हैं।

iOS 5 में आप का उपयोग कर सकते हैं:

[[UIBarButtonItem appearance] setTintColor:[UIColor greenColor]]; 

अधिक के लिए इन लिंक की जांच करें:

  1. UIAppearance Protocol
  2. User interface customization
+0

दस्तावेज़ीकरण के अनुसार यह आईओएस 5 के बाद से उपलब्ध है। उनका प्रश्न आईओएस 4 के लिए है। इसे यहां देखें .. http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html – iDev

+0

गरीब मिधुन। आज गलत प्रश्नों के अच्छे जवाब :) मुझे इस तरह के दिनों से नफरत है :) – rmaddy

+0

@rmaddy: मुझे लगता है कि आप सही हैं :) यह मेरे लिए एक बुरा दिन है :( –

2

नीचे कोड का प्रयास करें।

self.navigationController.navigationBar.tintColor = [UIColor greenColor]; 
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:nil action:NULL]; 
0

मैं जानता हूँ कि यह एक पुराने सवाल है, लेकिन इस मामले में किसी को भी एक customView उपयोग कर रहा है, तो आप की कोशिश कर सकते हैं:

myButton.customView.tintColor = [UIColor blackColor];