How to remove bottom shadow for navigationBar in swift3 - ios

I tried to set with empty image, but it not working
navigationController?.navigationBar.shadowImage = UIImage()

setting background image & shadow images working for me. Thanks #xingou
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = UIImage()

this is what the API document said :
The default value is nil, which corresponds to the default shadow image. When non-nil, this property represents a custom shadow image to show instead of the default. To show a custom shadow image, you must also set a custom background image with the setBackgroundImage(_:for:) method. If the default background image is used, then the default shadow image is used regardless of the value of this property.
so you need set the backgroundimage first.

Related

Tint Color works with native colors but not with the color from pattern image

I am theaming the navigation bar back button with the navigation bar tint color it works when I use native colors and it fails when I use custom color from an image.
working code :
self.navigationController?.navigationBar.tintColor = UIColor.orange
Not working code:
let color = UIColor.init(patternImage: someImage)
self.navigationController?.navigationBar.tintColor = color
Can someone show some light?
You cannot use pattern color for tint color.
Refer the following link:
https://developer.apple.com/documentation/uikit/uiview/1622467-tintcolor
look for this note:
Important
If you attempt to use a pattern color as a tint color, the system
raises an exception.
If you have a image then please set image in navigationbar as a background image. Like :
self.navigationController?.navigationBar.setBackgroundImage(#imageLiteral(resourceName: "NavigationBackground"), for: .default)
Hope this is helpful.

UIImageView tintColor colors whole image

I've tried changing the tintColor of a UIImageView inside a UICollectionViewCell after a tap by setting render mode of the icons to Template Image and then setting the color by calling
iconView.tintColor = .blue
Problem: This fills the whole image with the chosen color, Instead of just changing the non-transparent parts.
This method has been working for me in the past, and I'm unable to figure out the problem. I assumed that the icons might have a white background instead of a transparent one, but that's not the case. Maybe it has something to do with the UIImageView being inside a UICollectionViewCell?
Help would be highly appreciated!
try this
imageViewHome.image = UIImage.init(named: "yourImageName")?.withRenderingMode(.alwaysTemplate)
imageView.tintColor = .blue
The following code will color only the non transparent area.
yourImage.image = yourImage.image!.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
yourImage.tintColor = UIColor.redColor()
Happy coding.

How to make a UITabBarItem ignore the tintColor

I have a UITabBar with 5 tabs.
I set an "unselectedImage" to tabBarItem's image property and "selectedImage" to tabBarItem's selectedImage property.
The "selectedImage" is an image with a gradient, but it presents it in the color of the tabBar.tintColor.
So how can I cancel the tintColor and make the original image to be presented (without coloring it with the tintColor)?
Thanks!
When you set the image, define the rederingMode:
yourUIImage.renderingMode = alwaysOriginal

How can I remove border bottom of UINavigationBar?

I want to remove the bottom border from UINavigationBar, but I don't know how to remove it.
Actually, that is the shadow of the navigation bar.
To get rid of it, just set it to an empty image:
navigationController.navigationBar.shadowImage = UIImage()
Note: You must set it to an empty UIImage(); nil won't work for some reason.
You need to set a custom shadow image to show instead of the default one. Note: a custom background image must also be set.
navController.navigationBar.barTintColor = .blue //set your color
navController.navigationBar.isTranslucent = false
navController.navigationBar.setBackgroundImage(UIImage(), for: .default)
navController.navigationBar.shadowImage = UIImage()
you can do this
self.navigationController.navigationBar.layer.borderWidth = 0.0;
OR
you can give border color same as navigation bar background color
self.navigationController.navigationBar.layer.borderColor = [UIColor colorWithRed:<#(CGFloat)#> green:<#(CGFloat)#> blue:<#(CGFloat)#> alpha:<#(CGFloat)#>];
For iOS 11 you can use the (deprecated) Black Translucent Navigation bar style with a custom bar tint.

how to set alpha on Backgroung image using Swift

I have a button with background image and need to set the alpha to 0.5. How can I do this in swift?
This is my code that set the button background image
centerButton.setBackgroundImage(UIImage(named: "buttonImage"), forState: UIControlState.Normal)
Thanks
if you want to set alpha on only background image, then re-create UIImage with changing the alpha value.
if you want to set alpha to entire button, then simply set alpha value to the button.
centerButton.alpha = 0.5
I think you must create UIImage instance first and change alpha, then, setBackgroundImage to your button.
You can check: How to set the opacity/alpha of a UIImage?

Resources