Transparent UINavigationBar without border - ios

With iOS 7, it's now pretty easy to add a blur to UINavigationBar, even with a BarTint, see http://blog.ashleynh.me/frosted-uinavigationbar/ and this example image:
However, there's a border at the bottom. How can I get rid of the border to look more like this?
UPDATE:
I took Danny and Shali's code, and here are the results. As you can see, the border doesn't show any more but there is no blur.
let navigationBarAppearance = UINavigationBar.appearance()
navigationBarAppearance.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
navigationBarAppearance.shadowImage = UIImage()
navigationBarAppearance.translucent = true
and here's the Inspector screenshot:
I also tried:
let navigationBarAppearance = UINavigationBar.appearance()
let clearImage = UIImage.imageWithColor(UIColor.clearColor())
navigationBarAppearance.setBackgroundImage(clearImage, forBarMetrics: UIBarMetrics.Default)
navigationBarAppearance.shadowImage = clearImage
navigationBarAppearance.translucent = true
Same result, but the Inspector is a little different:

Apple Documents: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UINavigationBar_Class/index.html#//apple_ref/occ/instp/UINavigationBar/shadowImage
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. For a custom shadow image to be shown, a
custom background image must also be set with the
setBackgroundImage:forBarMetrics: method. If the default background
image is used, then the default shadow image will be used regardless
of the value of this property.
So basically you need to set background image before setting shadowImage to make it work.
Edit
Image generated from color (Swift) as background Navigation. Not sure if your blur function will still work when you change backgroundImage for Navigation bar. That would be a different problem.
class func imageWithColor(color: UIColor) -> UIImage {
let rect = CGRectMake(0, 0, 1, 1)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
color.setFill()
UIRectFill(rect)
var image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}

Have you tried navigationBar.shadowImage = [UIImage new]; ?

Related

Custom Tab Bar Background Image is not showing correctly

I'm implementing a custom Tab bar for my iOS app. Im using the following code to display a background image:
class TabNavigationMenu: UIView {
// ...
// ...
UIGraphicsBeginImageContext(self.frame.size)
UIImage(named: "tabBarbg.png")?.draw(in: self.bounds)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
if let image = image {
self.backgroundColor = UIColor(patternImage: image)
}
}
However, the tab bar is presented like this:
Also, when i make a view and present it anywhere else in the screen, it displays correctly. I'm using the same code there as well. Heres an example:
Any idea what the problem could be? I'm guessing the solution would also solve the faint blue line on top of the view...
You can try this to customize tab bar in ios
//Set the background color
UITabBar.appearance().backgroundColor = .red
tabBar.backgroundImage = UIImage(named: "tabBarbg.png")
//Set the item tint colors
tabBar.tintColor = .white
tabBar.unselectedItemTintColor = .lightGray

UITableViewCell: Change checkbox border colour

May I know how can I change the checkbox border colour of UITableViewCell?
You can try adding tint colour to the check mark image before assigning the image to the image view.
let borderImage = self.image?.withRenderingMode(.alwaysTemplate)
self.image = templateImage
self.tintColor = newValue
You can also add it through storyboard by selecting the image view and adding tint color to it.

Set UIImageView tintColor with multiple colors

I have this png image.
How can I change this blue color (only) to a different color in swift.
This because I might need to change to many different colors.
Even better if its possible to change the black color to white.
you can try like this:
self.img.image = self.img.image?.withRenderingMode(.alwaysTemplate)
self.img.tintColor = UIColor.black
let tableImage: UIImageView = {
let image = UIImageView()
image.image = image.withRenderingMode(.alwaysTemplate)
image.tintColor = .white
return image
}()
try this, this will change your image tintColor. I don't think you can set mutiple colors in image

Setting background image for a non-translucent navigation bar swift 4

I wanna change the background color of my navbar, while set the translucency to false, It's just plain white and it won't change untill I set an image for the background color. any help would be appreciated.
let homeViewController = HomeViewController();
let navigationController = UINavigationController(rootViewController: homeViewController);
let navBar = navigationController.navigationBar;
navBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white];
navBar.setBackgroundImage(UIImage(), for: .default);
navBar.shadowImage = UIImage();
navBar.isTranslucent = false;
navBar.backgroundColor = UIColor.red; //not working
navBar.tintColor = UIColor.red //not working
* EDIT *
Thank you so much you guys, yea that was it, can you please help me a bit further. the reason I wanted to change the color of navbar was because I wanted to make it transparent so I could add a gradient background to it, and with barTintColor now I could set it to clear.
but still this
navBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white];
navBar.setBackgroundImage(UIImage(), for: .default);
navBar.shadowImage = UIImage();
navBar.isTranslucent = false;
navBar.barTintColor = .clear;
doesn't work and I still don't see my gradient which I set like this :
let bg = UIImageView(image: UIImage(named: "gradient"));
bg.frame = CGRect(x: 0, y:0, width: UIApplication.shared.statusBarFrame.width, height: UIApplication.shared.statusBarFrame.height + (navBar.frame.height));
bg.contentMode = .scaleAspectFill;
bg.layer.masksToBounds = true;
bg.layer.opacity = 1;
navigationController.view.insertSubview(bg, belowSubview: navBar);
The reason I'm not just setting the background image with setBackgroundImage is I wanna change the position of the background image in the navbar so it should be on the right of the navbar.
I know I got the answer to my question but this was the real one and still can't figure it out. I'm gonna mark the best answer anyway either if you guys answer me or not but I would really appreciate if you could help me further.
EDIT *
Added Image
You set the wrong property.
Set barTintColor to apply your background color:
navBar.barTintColor = UIColor.red
Here's the Apple docs: barTintColor
This property is for Bar Text Color.
navBar.tintColor
Use This: (for NavBar Background Color).
navBar.barTintColor

TabBar icon becoming a rectangle when its state is selected

I use two icons for different states tabBarItem.
My problem is that when tabbar is selected one icon to become a rectangle.
I did the other icons, and they appear well. I was looking for any information not found on this topic. How can I fix it?
My code
override func viewDidLoad() {
super.viewDidLoad()
let triviaMainTableViewController = StoryboardManager.triviaStoryboard.instantiateViewControllerWithIdentifier("TriviaMainTableViewController") as! TriviaMainTableViewController
viewControllers = [triviaMainTableViewController]
tabBarItem.image = UIImage(named: "TriviaTabBarDefault")?.imageWithRenderingMode(.AlwaysOriginal)
tabBarItem.selectedImage = UIImage(named: "TriviaTabBarSelected")
tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -3)
navigationBar.barTintColor = ColorManager.greenColor
}
You need to make sure you have put your icon on a transparent background in order for the selection highlight to work correctly. If the background color of the image isn't transparent it may look fine when it is not selected, but not when it is selected.

Resources