2012-02-23 14 views
17

यह कोड एप्लिकेशन के भीतर हर जगह UINavigationBar का रंग बदल सकता है। हालांकि, मैंने देखा कि UINavigationBar केUINavigationController द्वारा उपयोग किया गया है (मेरा UIStoryboard से आता है)।UINavigationController नेविगेशन बार टिंट रंग को वैश्विक स्तर पर और प्रोग्रामेटिक रूप से बदलें

UIColor* navBarColor = [UIColor colorWithRed:arc4random()%100/100.0 
             green:arc4random()%100/100.0 
             blue:arc4random()%100/100.0 
             alpha:1]; 
[[UINavigationBar appearance] setTintColor:navBarColor]; 

[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent]; 
[[UINavigationBar appearance] setAlpha:0.7]; 

वहाँ एक UINavigationController's नेविगेशन पट्टी के appearance वस्तु पहुंचने का एक तरीका है? मुझे पता है कि व्यक्तिगत नियंत्रकों के टिनट कैसे सेट करें, लेकिन मैं वैश्विक नियंत्रण रखना चाहता हूं कि वे कैसे दिखते हैं।

अद्यतन: यह था मेरी गलती, कोड सभी UINavigationBars की UIColor बदलने करता, लेकिन यह (उदाहरण के एक मॉडल दृश्य नियंत्रक पेश करने के लिए) को कवर किया और पर्दाफाश किए जाने की जड़ नेविगेशन नियंत्रक की आवश्यकता है, तो यह होगा फिर से ड्रा खुद को UIColors के साथ!

धन्यवाद!

उत्तर

4

पूर्ण समाधान जो नेवबार रंग तुरन्त बदल जाता है और बाद में प्रक्षेपण के लिए वरीयता याद रखता है यहां पाया जा सकता: iPhone iOS how to redraw UINavigationBar on demand?

13

जब आप अपने UINavigationController घोषणा करते हुए इस प्रयास करें:

UINavigationController *myNavController = 
[[UINavigationController alloc] initWithRootViewController:myRootViewController]; 
myNavController.navigationBar.tintColor = 
    [UIColor colorWithRed:arc4random() % 100/100.0f 
        green:arc4random() % 100/100.0f 
        blue:arc4random() % 100/100.0f 
        alpha:1.0f]; 
13

आप बदल सकते हैं appearance प्रॉक्सी का उपयोग करके विश्व स्तर पर बार रंग:

NSDictionary *textTitleOptions = 
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], 
              UITextAttributeTextColor, 
              [UIColor whiteColor], 
              UITextAttributeTextShadowColor, nil]; 

[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions]; 
textTitleOptions = 
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], 
              UITextAttributeTextColor, nil]; 
[[UINavigationBar appearance] setTintColor:[UIColor redColor]]; 
[[UIToolbar appearance] setTintColor:[UIColor redColor]]; 
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]]; 
+1

ध्यान दें कि 'UITextAttributeTextColor' और' UITextAttributeShadowColor' अमान्य हो जाने - 'NSForegroundColorAttributeName' और' NSShadowAttributeName' बजाय का उपयोग करें। – thomers

13

नहीं iOS 8 में डब्ल्यू हम इस से टिंट रंग सेट कर सकते हैं: -

self.navigationController.navigationBar.barTintColor = [UIColor redColor]; 
संबंधित मुद्दे