मैं अपने दाएं बार बटन आइटम का रंग काला से सफेद में बदलना चाहता हूं। यह एक खोज आइकन के रूप में एक बटन है। मैंने अभी तक खोज कार्यान्वयन को कोड नहीं किया है क्योंकि मैं मुख्य इंटरफेस को पहले पूरा करना चाहता हूं। मैंने सोचा कि मैंने सही कोड लिखे हैं, इसलिए इसे सफेद के रूप में दिखाना चाहिए, लेकिन ऐसा लगता है कि स्टोरीबोर्ड और सिम्युलेटर दोनों में अभी भी काले रंग के रूप में दिखाई देता है।स्विफ्ट में UIBarButtonItem के tintColor को कैसे बदलें?
स्टोरीबोर्ड में, मैंने इसे सफेद पर भी सेट किया है।
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Changing the status bar's colour to white
UIApplication.sharedApplication().statusBarStyle = .LightContent
// Changing the navigation controller's background colour
UINavigationBar.appearance().barTintColor = UIColor(red: 0.0/255.0, green: 165.0/255.0, blue: 227.0/255.0, alpha: 1.0)
// Changing the navigation controller's title colour
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
// Changing the colour of the bar button items
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
// Changing the tint colour of the tab bar icons
UITabBar.appearance().tintColor = UIColor(red: 0.0/255/0, green: 165.0/255.0, blue: 227.0/255.0, alpha: 1.0)
return true
}
यहाँ सिम्युलेटर की एक छवि है:
यहाँ मेरी कोड है, जो AppDelegate.swift
फ़ाइल में स्थित है
मैं यह अजीब लगा कि लगता है कोड की इस पंक्ति काम नहीं करता कोई भी समाधान?
क्या आपने 'UIBarButtonItem.appearance() की कोशिश की है। TintColor = UIColor.greenColor()' –
@RashwanL मैंने कोशिश की, लेकिन यह अभी भी काला है। मैं इसे सफेद होना चाहता हूँ। –
'UINavigationBar.appearance()। TintColor = UIColor.whiteColor() 'काम करना चाहिए। आपको अपने कोड – Leo