Remove UINavigationBar border [duplicate] - swift

This question already has answers here:
How to hide UINavigationBar 1px bottom line
(49 answers)
Closed 7 years ago.
There is a thin gray border in the bottom of UINavigatioBar:
I can't remove it!
I've tried:
self.navigationController?.navigationBar.layer.borderColor =
UIColor.orangeColor().CGColor
self.navigationController?.navigationBar.layer.borderWidth = 0
With no chance.

It should work
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
Add this line for background color (Change rgb value of your choice)
self.navigationController?.navigationBar.barTintColor = UIColor(rgba: "#000000")

Related

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

UIBarButtonItem is too wide [duplicate]

This question already has answers here:
Change size of UIBarButtonItem (image) in Swift 3
(8 answers)
Closed 3 years ago.
I am trying to add a UIBarButtonItem to my UINavigationController.
The button is too wide though and the hit area seems to stretch beyond the bounds of the image.
In my viewDidLoad I am simply applying:
let leftNavButton = UIBarButtonItem(image: #imageLiteral(resourceName: "hamburger_icon"), style: .plain, target: nil, action: nil)
navigationItem.leftBarButtonItem = leftNavButton
There can be a problem with an image size of hamburger_icon, try to use a random system icon to see if the image is still too wide.

How to add a border to swift navigationBar after removing it

I use:
self.navigationController?.navigationBar.shadowImage = UIImage()
to remove the border of a navigationBar earlier in my app but now I'm not sure to add the border back on a later screen.
To reset the navigationBar's shadowImage to the default shadowImage do the following:
self.navigationController?.navigationBar.shadowImage = UINavigationBar().shadowImage

How to set navigation bar to solid color [duplicate]

This question already has answers here:
Change the color of iOS Navigation Bar
(10 answers)
Changing navigation bar color in Swift
(36 answers)
Closed 4 years ago.
When I change the background color of the navigation bar, it is opaque like the following.
UINavigationBar.appearance().backgroundColor = .black
Then if I set translucent to false, I don't see any color like the following
UINavigationBar.appearance().backgroundColor = .black
UINavigationBar.appearance().isTranslucent = true
Any idea on how to make a solid background color?
Set it's barTintColor
Example:
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().barTintColor = .red
You should set the barTintColor instead of the backgroundColor:
The tint color to apply to the navigation bar background.
https://developer.apple.com/documentation/uikit/uinavigationbar/1624931-bartintcolor
UINavigationBar.appearance().barTintColor = .black

Swift UiButton how to left align the title? [duplicate]

This question already has answers here:
Trouble left-aligning UIButton title (iOS/Swift)
(2 answers)
Closed 2 years ago.
I have a UIButton created programmatically but can't find a way to left align the title.
This does nothing:
button.setTitle("DESCRIPTION", for: .normal)
button.titleLabel?.textAlignment = .left
Try this one
button.contentHorizontalAlignment = .left
For left side aligment:
buttonItem.contentHorizontalAlignment = .left
For right side aligment:
buttonLogout.contentHorizontalAlignment = .right
and bydefault alignment for button title is center.