how can I remove the top border on UIToolBar

IphoneObjective CIosIpad

Iphone Problem Overview


I have set my UIToolBar tint color to some value, and there is this border line that I see in which I want to remove:

enter image description here

How do I remove this black border>

Iphone Solutions


Solution 1 - Iphone

You can do like this:

self.navigationController.toolbar.clipsToBounds = YES;

Solution 2 - Iphone

toolbar1.clipsToBounds = YES;  

Worked for me incase someone is still trying with Navigational bar

Solution 3 - Iphone

Correct answer is the one by totalitarian...FYI. https://stackoverflow.com/a/14448645/627299

My response is still below for reference.


Here's what I did with my WHITE background toolbar...

whiteToolBar.layer.borderWidth = 1;
whiteToolBar.layer.borderColor = [[UIColor whiteColor] CGColor];    

Perhaps you could do the same thing with your color instead.

Solution 4 - Iphone

setShadowImage to [UIImage new]

Solution 5 - Iphone

navigationController?.toolbar.barTintColor = .white

navigationController?.toolbar.setShadowImage(UIImage(), forToolbarPosition: .any)

enter image description here

Solution 6 - Iphone

Setting the style to UIBarStyleBlackTranslucent did it for me (iOS 6)

Solution 7 - Iphone

create a 1 pixel x 1 pixel clear image and call it clearPixel.png

toolbar.setShadowImage(UIImage(named: "clearPixel.png"), forToolbarPosition: UIBarPosition.any)

Solution 8 - Iphone

this doesn't work consistently on iOS versions, doesn't seem to work on iOS7. i answered this in another question: https://stackoverflow.com/a/19893602/452082 and you can modify that solution to just remove the background shadow (and leave your toolbar.backgroundColor whatever color you like)

Solution 9 - Iphone

The clipsToBounds technique clips the UIToolBar's shadow as well as the background view. On an iPhone X, that means the background no longer reaches outside the safe area.

Incorrect UIToolBar on iPhone X

The solution below uses a mask to clip only the top of the UITabBar. The mask is rendered in a UIToolBar subclass, and the mask frame is kept updated in an override of layoutSubviews.

class Toolbar: UIToolbar {
    
    fileprivate let maskLayer: CALayer = {
        let layer = CALayer()
        layer.backgroundColor = UIColor.black.cgColor
        return layer
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        initialize()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        initialize()
    }
    
    fileprivate func initialize() {
        layer.mask = maskLayer
        // Customize toolbar here
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        // height is an arbitrary number larger than the distance from the top of the UIToolbar to the bottom of the screen
        maskLayer.frame = CGRect(x: -10, y: 0, width: frame.width + 20, height: 500)
    }
    
}

Correct UIToolBar on iPhone X

Solution 10 - Iphone

I got a bit confused with these answers but I was missing the point that you were using an Outlet so just to be clear here is the swift code I used to hide the border:

import UIKit

class ViewController: UIViewController {

    //MARK Outlets
    @IBOutlet weak var ToolBar: UIToolbar!
    
    //MARK View Functions
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        // Hide the bottom toolbar's top border
        ToolBar.clipsToBounds = true
    }
}

I had dragged a toolbar to the bottom of a view for this and it's not the top nav bar some other questions refer to.

Solution 11 - Iphone

[[UIToolbar appearance] setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionBottom barMetrics:UIBarMetricsDefault];

[[UIToolbar appearance] setShadowImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionBottom];

[UIToolbar appearance].barTintColor = [UIColor ...];```

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaditView Question on Stackoverflow
Solution 1 - IphonetotalitarianView Answer on Stackoverflow
Solution 2 - IphoneRavi Mudaliar - SeffconView Answer on Stackoverflow
Solution 3 - IphoneKeenanView Answer on Stackoverflow
Solution 4 - IphoneCherpak EvgenyView Answer on Stackoverflow
Solution 5 - IphonedamoView Answer on Stackoverflow
Solution 6 - IphoneDrMickeyLauerView Answer on Stackoverflow
Solution 7 - IphonealionthegoView Answer on Stackoverflow
Solution 8 - IphonenatbroView Answer on Stackoverflow
Solution 9 - IphoneAlexView Answer on Stackoverflow
Solution 10 - IphoneGazBView Answer on Stackoverflow
Solution 11 - Iphonecoolcool1994View Answer on Stackoverflow