您好,我正在尝试将UISearchbar更改为矩形,而不是圆角矩形,并将其与具有相同颜色的导航栏合并。
导航栏的背景颜色应与搜索栏的背景颜色相同,但有区别,并且有清晰的边缘显示,两者都应显示背景颜色#be1b25而不是#bc303a。同样,文本字段仍显示圆角矩形而不是完整矩形。
主视图控制器代码
@IBOutlet weak var searchBar: UISearchBar!
self.navigationController?.navigationBar.isTranslucent = true
navigationController?.navigationBar.backgroundColor = UIColor().HexToColor(hexString: REDCOLOR)
searchBar.backgroundColor = UIColor().HexToColor(hexString: REDCOLOR)
searchBar.tintColor = UIColor().HexToColor(hexString: REDCOLOR)
searchBar.barTintColor = UIColor().HexToColor(hexString: REDCOLOR)
searchBar.barStyle = .default
searchBar.placeholder = NetworkManager.sharedInstance.language(key: "searchentirestore")
searchBar.layer.cornerRadius = 0;
searchBar.clipsToBounds = false;
searchBar.barTintColor = UIColor().HexToColor(hexString: REDCOLOR)
searchBar.layer.borderWidth = 0
//searchBar.layer.borderColor = UIColor.clear as! CGColor
UISearchBar扩展
extension UISearchBar {
private var textField: UITextField? {
return subviews.first?.subviews.flatMap { $0 as? UITextField }.first
}
private var activityIndicator: UIActivityIndicatorView? {
return textField?.leftView?.subviews.flatMap{ $0 as? UIActivityIndicatorView }.first
}
var isLoading: Bool {
get {
return activityIndicator != nil
} set {
if newValue {
if activityIndicator == nil {
let newActivityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
newActivityIndicator.transform = CGAffineTransform(scaleX: 0.7, y: 0.7)
newActivityIndicator.startAnimating()
newActivityIndicator.color = UIColor().HexToColor(hexString: BUTTON_COLOR)
newActivityIndicator.backgroundColor = UIColor.white
textField?.leftView?.addSubview(newActivityIndicator)
let leftViewSize = textField?.leftView?.frame.size ?? CGSize.zero
newActivityIndicator.center = CGPoint(x: leftViewSize.width/2, y: leftViewSize.height/2)
}
} else {
activityIndicator?.removeFromSuperview()
}
}
}
请帮助,这是Swift3。在此先感谢
答案 0 :(得分:0)
所以您要处理一些事情
UISearchbar
UISearchbar
的子视图并更改其右子层的拐角半径,但这是一个 hack ,Apple可以更改该层次结构,您将再次处于起步阶段< / li>
UISearchbar
,很少的UIView和带有某些UIImageView的UITextfield
。UISearchController
UIView
中的NavBar下方,而不是在导航中,但是在这种情况下 NavBar不能半透明,因为您将永远无法获得相同的色彩空间 UIView
添加到NavBar中的titleView
答案 1 :(得分:0)
将 UISearchBar 设置为NavigationController的titleView
<script type="module" src="es6://main.js"></script>