iOS8 Swift TabBarController Change Icon Color - swift

I'm trying to change the color of the icons in my TabBarController.
I've successfully changed the textcolor (just below the icons), but cant figure out how I change the icon color.
I've changed the icon-text-color like this:
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState:.Selected)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState:.Normal)
I've put this into my AppDelegate.swift (didFinishLaunchingWithOptions).
Now the selected item-text is orange, and the unselected are white.
The icons however are still in blue / dark gray. How do I change these?
Unselected:
Selected:

being tBVC my tabBarViewController, I just do:
tBVC.tabBarItem.selectedImage = UIImage(named: "k-lenda(Hi)")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
tBVC.tabBarItem.image = UIImage(named: "k-lenda(Lo)")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
And in the attributes inspector I have the "Hi" image for the Bar Item.
I hope it helps !

Set tintColor property by UIAppearance.

Related

why toolbar text color always white in SwiftUI project

I have a problem in my SwiftUI project. In toolbar text buttons color is white, even I add this code
init() {
UIToolbar.appearance().barTintColor = UIColor.red
}
there is not any change, I do not know why? Any idea?
You could set an accent color to the view like this:
.accentColor(Color.red)

How to change programatically top bar background swift 4 on iOS 13

I want to change the status and navigation bar from colored to transparent and from transparent to colored.
How can I do this?
enter image description here
navigationController?.navigationBar.barTintColor = .green // Set Background Color
navigationController?.navigationBar.barTintColor = .none // remove Background Color

How can I change the background color of the arrow in an iOS popover in Swift?

When I set the background color of a UIView in the storyboard to a specific color (e.g. black) the arrow of the popup remains unchanged (e.g. white).
How can I change the color of the arrow too?
If you want to see the arrow of a popover in the same color like the background color of the popover, add the following line in the "viewDidLoad()" method in your UIViewController (the "popup"):
override func viewDidLoad() {
super.viewDidLoad()
self.popoverPresentationController?.backgroundColor = self.view.backgroundColor
}
iOS popover with changed background color

UINavigationBar titleTextAttributes does not update fully after reloading views

This is a tricky one.
Here is my storyboard for this demo:
The Settings screen segues to the My Color screen where users can choose either a dark or light color scheme for the app. When a change is made, I remove all views from the window and then re-add them to force the current view to immediately apply the changes via the UIAppearance proxy. So the color of the navigation bar and the nav bar's text color both change immediately.
Next, the user unwinds the segue to return to the Settings screen. On the Settings screen, the new color of the navigation bar is already applied. The new color of the nav bar's text is also already applied. However, for a brief instant while the segue is in transition, the nav bar still shows the old text color. The new text color is not shown until after the transition is complete. This results in a minor, but noticable, visual glitch as the nav bar's text suddenly changes from the old color to the new color.
To update the color of the nav bar text when the user flips the switch, I run the following code in the My Color screen's view controller. (The full project code up on Github at https://github.com/prinomen/social_demo2).
func switchValueDidChange(sender:UISwitch!) {
if (sender.on == true) {
colorIndex = 1 // nav bar is now black
UINavigationBar.appearance().barTintColor = black // set appearance proxy to the new color
// Run this switch to set the textColor global var to match the preferred color scheme, based on the value of colorIndex.
switch colorIndex {
case 0: // white
textColor = green
statusBarTextIsBlack = true
case 1: // black
textColor = red
statusBarTextIsBlack = false
default:
break;
}
// Update these appearance proxy items (they need the window to reload before they will manifest their changes).
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir-Medium", size: 22)!, NSForegroundColorAttributeName: textColor]
UINavigationBar.appearance().tintColor = textColor
// Remove all views from the window and then re-add them in order to force the current view to immediately apply changes to UIAppearance.
let windows : NSArray = UIApplication.sharedApplication().windows
for window in windows as! [UIWindow] {
for view in window.subviews {
view.removeFromSuperview()
window.addSubview(view)
}
}
} else {
colorIndex = 0 // nav bar is now white
UINavigationBar.appearance().barTintColor = white // set appearance proxy to the preferred color
// Run this switch to set the textColor global var to match the preferred color scheme, based on the value of colorIndex.
switch colorIndex {
case 0: // white
textColor = green
statusBarTextIsBlack = true
case 1: // black
textColor = red
statusBarTextIsBlack = false
default:
break;
}
// Update these appearance proxy items (they need the window to reload before they will manifest their changes).
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir-Medium", size: 22)!, NSForegroundColorAttributeName: textColor]
UINavigationBar.appearance().tintColor = textColor
// Remove all views from the window and then re-add them in order to force the current view to immediately apply changes to UIAppearance.
let windows : NSArray = UIApplication.sharedApplication().windows
for window in windows as! [UIWindow] {
for view in window.subviews {
view.removeFromSuperview()
window.addSubview(view)
}
}
}
}
Aside from changing the color via the appearance proxy, I've also tried setting the color explicitly within the viewWillAppear and viewWillLayoutSubviews methods of the Settings screen view controller by running this line:
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "Avenir-Medium", size: 22)!, NSForegroundColorAttributeName: textColor]
But this results in the same issue. What I find confusing is that the other changes made via the appearance proxy are updated without encountering this issue. Only the titleTextAttributes property is troubled by this issue.
I thought that maybe iOS makes some kind of "snapshot" of the Settings screen when segueing to the My Color screen. Then when the segue is reversed, the "snapshot" with the old nav bar text color is used and the new color is not updated until the segue is finished. But if that were true, then why doesn't the navigation bar's barTintColor also experience the same problem? There must be a different way the reverse segue is handled, but I can't seem to figure it out.
Is there a way to apply the color change to the title text before the transition happens, in a way that affects the transition itself?
Thanks for any insight!

Change the tint color of the ActionSheet that appears when you long tap on a link in a WKWebView

I'm writing an iOS 8 app and this problem is driving me crazy... I've set the tint color of my window in white (because I've got colored toolbar and navigation bar) but now, when in my WKWebView I long press on a Link, the actions titles of the Action Sheet that appears are written in White and so it's very difficult to read them.
Is there a way to change the tint color of this object?
I tried with
UIActionSheet.appearance.tintColor but it doesn't work, perhaps that control is not a UIActionSheet?
Thank you
Dave
I haven't found a solution but I've found a workaround: I set the tint color of the window as I like and then I set just the navigation bar's tint color and the toolbar's tint color in white.
This work for me, Swift 2.1 xCode 7 :
let actionSheet = UIActionSheet(title: "Launch your GPS navigator", delegate: self,
cancelButtonTitle: "Cancel", destructiveButtonTitle:
"Cancel", otherButtonTitles:"Open path in Google Maps"
, "Open path in Maps", "Open path in Waze")
if actionSheet.respondsToSelector("_alertController") {
let alertController = actionSheet.valueForKey("_alertController")
if ((alertController?.isKindOfClass(UIAlertController)) != nil) {
alertController?.view??.tintColor = UIColor.redColor
}
}
actionSheet.showInView(self.view)