How can I change the background color of the arrow in an iOS popover in Swift? - 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

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)

Swift how to remove uisegmentControl default black backgroundColor?

I know a lot of people asked this question, but nothing helps. My controller1 presents a new controller2 from storyboard. Controler1's background color is black. My customized segmentcontrol background color and selectedTintColor work well, but always show a black background color first. I tried every way, but not working. In storyboard and code, all no this black color. Thanks!
override func viewDidLoad() {
let bgColor = uIColor. // my customized color)
segmentControl.backgroundColor = bgColor
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
connectionSegmentControl.selectedSegmentIndex = 0
toggleSegmentTintColor()
}
private func toggleSegmentTintColor() {
// I set my customized selected tint color here, it works.
}
If you do this in viewDidAppear, its too late: the view is on the screen. The hack way to do it is in viewDidlaod or viewWillAppear. The right way to do it is to to use UIAppearance proxy on app launch to set the tint color for your object globally:
UISegmentedControl.appearance().tintColor = UIColor.clear
You can also set the tint color for the whole app by setting it on the root window, but then it affects more than just the segmented controls.

Erase borders between navigation bar and searchBar swift 4

I am setting both the navigation bar and the search bar to a custom UIColor (which I call categoryColor in my code). When I do that, I still see an upper grayish line between nav bar and search bar. I have already set the searchBar border color to be the same as the others, but that gray line still exists. Does anyone know how to get rid of it?
Here is my code:
override func viewWillAppear(_ animated: Bool) {
//defining the color that will be used for all the items
let categoryColor = UIColor(hexString: selectCategory?.categoryColorHex ?? UIColor.randomFlat.hexValue())
//changing navigation bar tint color
navigationController?.navigationBar.barTintColor = categoryColor
//changing searchbar tint color
searchBar.barTintColor = categoryColor
//change searchBar border's color
searchBar.layer.borderColor = categoryColor?.cgColor
searchBar.layer.borderWidth = 3
//changing title that appears at the top, after list is loaded
title = selectCategory?.listName ?? "Todoey"
}
Here is a picture of what I see when I run the simulation:
The better way for implementing search bar with nav controller would be to use searchController inside a navigationController so the searchController will have the same background as navigationController. Here’s a great tutorial about that: https://m.youtube.com/watch?v=h7caxpp3Xps
Edit:
Also if you already implemented search capabilities you can do that with searchController too. Just set navigationController.searchConroller.searchBar.delegate for class that’s responsible for handling delegate methods

Swift - instance of backgroundColor not working

If I set up an image in the Image/Image View of the Attributes Inspector the following subsequent call does not work:
picture.backgroundColor = UIColor.greenColor()
If I setup the image in the code, such as in viewDidAppear, it does.
Am I missing something, is this a quirk and how do I get it to behave?
It does work. But you can't see it in some cases.
For example: in the following image I have change the background color and set it to aspect fit. The gap between the two appears in green. So the image must have some transparency to it in order to see the background color.
Image with white background
Image with transparent background
Edit:
This is how I changed the background color
#IBOutlet weak var picture: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
picture.backgroundColor = UIColor.greenColor()
}

iOS8 Swift TabBarController Change Icon Color

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.