How can I change the top border of my UITabBar?

TIMEX picture TIMEX · Sep 1, 2015 · Viewed 25.3k times · Source

I'd like the UITabBar to have a top border of width 5.0. The border should be yellow color. I don't want any left/bottom/right borders.

The Tab Bar border should be flat (no shadows or anything like that).

How can I remove shadow (image) line?

Answer

Dharmesh Kheni picture Dharmesh Kheni · Sep 1, 2015

You can hide the top border this way in your FirstViewController.swift:

self.tabBarController!.tabBar.layer.borderWidth = 0.50
self.tabBarController!.tabBar.layer.borderColor = UIColor.clear.cgColor
self.tabBarController?.tabBar.clipsToBounds = true

And result will be:

Before:

before - top border is visible

After:

after - top border is not visible

Hope it helps.

EDIT:

You can set background image this way:

UITabBar.appearance().backgroundImage = UIImage(named: "yourImageWithTopYellowBorder.png")