我创建了一个带有 UISearchBar 的 .xib。
顶部边框下方还有一个看起来像阴影的东西。
我尝试过更改背景/色调等,但很难让它消失。
欢迎任何帮助,有什么想法吗?
编辑
所以下面的代码允许我去掉顶部和底部的边框,但不能去掉奇怪的阴影。我添加了绿色背景以更清楚地显示它。
此外,在文本框(而不是 View )周围添加边框的最佳方法是什么?谢谢
//** 这就是我想要做的:https://stackoverflow.com/questions/33107058/uiviewcontroller-sizing-as-maincontroller-within-uisplitviewcontroller
这是我正在使用的代码。
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() {
}
}
最佳答案
将栏的 backgroundImage
设置为 empty UIImage
,not nil
:
searchBar.backgroundImage = UIImage()
您还可以设置 barTintColor
,正如您在下面的评论中指定的那样。
关于ios - 删除 UISearchBar 的上下边框和阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33146848/