I have created a .xib with a UISearchBar.
I am looking to remove the top and bottom borders as seen in this image:
There is also what looks like a shadow underneath the top border.
I have tried changing backgrounds/tint colours etc, but struggling to get it to disappear.
Any help would be welcome, any ideas?
EDIT
So the code below allows me to get rid of the border at the top and bottom, but not the weird drop shadow. I've added green background to show it more clearly.
Also, what would be the best way to add a border around the text box (rather than the view)?? Thanks
//** This is what I'm trying to do: https://stackoverflow.com/questions/33107058/uiviewcontroller-sizing-as-maincontroller-within-uisplitviewcontroller
and here is the code I am using.
import UIKit
class TopSearchViewController: UIView {
var expanded: Int = 0
@IBOutlet weak var trailingConstraint: NSLayoutConstraint!
@IBOutlet var contentView: UIView!
@IBOutlet weak var searchBar: UISearchBar!
@IBAction func advancedSearchButton(sender: AnyObject) {
if expanded == 0 {
self.layoutIfNeeded()
UIView.animateWithDuration(0.1, animations: {
self.trailingConstraint.constant = 200
self.layoutIfNeeded()
})
expanded = 1
} else {
self.layoutIfNeeded()
UIView.animateWithDuration(0.1, animations: {
self.trailingConstraint.constant = 25
self.layoutIfNeeded()
})
expanded = 0
}
}
override init(frame: CGRect) { // for using CustomView in code
super.init(frame: frame)
self.commonInit()
}
required init(coder aDecoder: NSCoder) { // for using CustomView in IB
super.init(coder: aDecoder)
self.commonInit()
}
private func commonInit() {
NSBundle.mainBundle().loadNibNamed("TopSearchViewController", owner: self, options: nil)
contentView.frame = self.bounds
contentView.autoresizingMask = .FlexibleHeight | .FlexibleWidth
self.addSubview(contentView)
self.searchBar.layer.borderWidth = 1
self.searchBar.layer.borderColor = UIColor.whiteColor().CGColor
println(searchBar)
for subview in searchBar.subviews {
println("hello")
var textField : UITextField
if (subview.isKindOfClass(UITextField)) {
textField = subview as! UITextField
textField.borderStyle = .None
textField.layer.borderWidth = 1
textField.layer.borderColor = UIColor.lightGrayColor().CGColor
textField.layer.cornerRadius = 14
textField.background = nil;
textField.backgroundColor = UIColor.whiteColor()
}
}
}
func viewDidLoad() {
}
}
Set the bar's backgroundImage
to an empty UIImage
, not nil
:
searchBar.backgroundImage = UIImage()
You may also set the barTintColor
, as you specified in your comment below.
With Xcode 11, in the Storyboard, you can set 'Search Style' to 'Minimal.'
In code: searchBar.searchBarStyle = .minimal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With