MFMailComposeViewController navigationBar custom background color - swift

I'm using MFMailComposeViewController and I'd like to change background color so it matches the one I have across the app. I've tried several things, but nothing worked(at least not on iOS 9).
let mailVC = MFMailComposeViewController()
mailVC.mailComposeDelegate = self
...
mailVC.navigationBar.titleTextAttributes =
[NSForegroundColorAttributeName: UIColor.whiteColor()] // this works
mailVC.navigationBar.tintColor = UIColor.whiteColor() // this works
mailVC.navigationBar.barTintColor = UIColor.blueColor() // this doesn't work
mailVC.navigationBar.backgroundColor = UIColor.blueColor() // this doesn't work
Background color stays default gray.

I solved it by setting color of navigationbar before initializing MFMailComposeViewController like this:
UINavigationBar.appearance().barTintColor = UIColor.blueColor()
let mailVC = MFMailComposeViewController()

Related

Remove Gradient and make Transparent navigation bar in ios 15

I have tried the following code to remove the gradient from navigation and make a transparent navigation bar for ios 15, But it didn't work on the same whereas in the lower version it works perfectly fine.
if let bar = self.navigationController?.navigationBar {
if #available(iOS 15.0, *) {
let navigationBarAppearance = UINavigationBarAppearance()
navigationBarAppearance.configureWithTransparentBackground()
navigationBarAppearance.shadowImage = UIImage()
self.title = ""
navigationBarAppearance.backgroundImage = UIImage()
navigationBarAppearance.backgroundColor = .clear
UINavigationBar.appearance().isTranslucent = true
UINavigationBar.appearance().standardAppearance = navigationBarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navigationBarAppearance
} else {
bar.setBackgroundImage(FCUtil.getImageWithColor(color: UIColor.clear, size: bar.frame.size), for: UIBarMetrics.default)
bar.isTranslucent = true
bar.shadowImage = UIImage()
self.title = ""
}
}
Please suggest to me, If I had missed something.
The only problem with your code is the timing. You are running the code too late. Changing the navigation bar appearance() cannot change a navigation bar that already exists.
Instead, just change bar itself, directly:
bar.standardAppearance = navigationBarAppearance
bar.scrollEdgeAppearance = navigationBarAppearance

Can't set the same color for background and border in UISegmentedControl

I am trying to customize my segmented control with Swift, but I have run into a problem. I set the same color (e.g. UIColor.red) for border and background, but they look different. My code is:
segmentedControl.layer.cornerRadius = 12
segmentedControl.layer.borderWidth = 2
segmentedControl.layer.borderColor = UIColor.red.cgColor
segmentedControl.layer.masksToBounds = true
segmentedControl.backgroundColor = .red
Maybe someone knows how can I fix it?
Try setting the tintColor and selectedSegmentTintColor:
segmentedControl.tintColor = .white
segmentedControl.selectedSegmentTintColor = .white

Curve search bar Swift 4 [duplicate]

This question already has answers here:
UISearchBar custom corners
(5 answers)
Closed 4 years ago.
i had problem to change my search bar design programatically on navigation controller. i just want to make the search bar curve like image below:
i had try a lot of example in stack overflow, but i still failed to change the shape. Here what it looks like now:
and here is the source code, on what have already done:
//MARK for searchBar UI
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.placeholder = " Search for programs..."
searchController.searchBar.sizeToFit()
searchController.searchBar.isTranslucent = false
searchController.searchBar.backgroundImage = UIImage()
searchController.searchBar.delegate = self
navigationItem.titleView = searchController.searchBar
self.searchController.searchBar.layer.cornerRadius = 20.0
self.searchController.searchBar.clipsToBounds = true
// SearchBar text
let textFieldInsideUISearchBar = searchController.searchBar.value(forKey: "searchField") as? UITextField
textFieldInsideUISearchBar?.borderStyle = .roundedRect
textFieldInsideUISearchBar?.font = textFieldInsideUISearchBar?.font?.withSize(14)
and now, i really have no idea how to change it, thanks in advance.
This will help you,
let searchBar = UISearchBar()
On viewDidLoad()
searchBar.sizeToFit()
searchBar.placeholder = "Search"
self.navigationController?.navigationBar.barTintColor = UIColor.green //this is just for reference
self.navigationItem.titleView = searchBar
if let textfield = searchBar.value(forKey: "searchField") as? UITextField {
textfield.textColor = UIColor.blue
if let backgroundview = textfield.subviews.first {
backgroundview.backgroundColor = UIColor.blue
backgroundview.layer.cornerRadius = 20;
backgroundview.clipsToBounds = true;
}
}
Above code will give you following output,
increasing the corner radius should work

Colorize image, take the wrong color swift

I want to colorize an image from an imageView. After that I want to set this image to a button.
let imageView:UIImageView = UIImageView()
if let myImage = UIImage(named: "ic_star") {
let tintableImage = myImage.imageWithRenderingMode(.AlwaysTemplate)
imageView.image = tintableImage
}
imageView.tintColor = UIColor.redColor()
bestListButton.setImage(imageView.image, forState: .Normal)
This is a snippet, that should work, but it colorize my button-image always in blue.
The debugger say that the color doesn't change. And the simulator change it in blue.
It seems that it doesn't have something to do with my backgroundcolor of image.
EDIT and (hack) solution
Okay, it's quite strange. The blue is because in my interface builder was the tintColor blue.
I changed it to white. Now my star is white.
BUT: When I delete my code, the image switch back to black. So the change of color seems just work in combination with interface builder and code.
EDIT 2
Programmatically solution:
bestListButton.tintColor = UIColor.redColor()
Is your image a PNG file?
Try:
let imageView:UIImageView = UIImageView()
if let myImage = UIImage(named: "ic_star") {
imageView.image = imageView.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
}
imageView.tintColor = UIColor.redColor()
bestListButton.setImage(imageView.image, forState: .Normal)

SKLightNode: Changing alpha of ambientColor

Is there a way to change the alpha value of an SKLightNodes ambientColor so that e.g. their background can be seen even if the lightNode is on the other side of the screen?
//Add LightNode
let lightNode = SKLightNode()
lightNode.ambientColor = UIColor.blackColor()
lightNode.lightColor = UIColor.whiteColor()
lightNode.shadowColor = UIColor.blackColor()
lightNode.categoryBitMask = LightCategory.Light1.rawValue
lightNode.enabled = true
lightNode.falloff = 0.05
self.addChild(lightNode)
//Sprite
sprite.lightingBitMask = LightCategory.Light1.rawValue
It says here in the SKLightNode Class Reference that, "The alpha value of the color is ignored." If you want things on the other end of the screen to be visible, you should change the falloff.