我正在一个项目中,我想要带有圆角半径的搜索栏。我制作了自定义的searchbar类,并继承了超级UISearchBar类,并在awakeFromNib中应用了此类代码。
class SearchBar: UISearchBar{
override func awakeFromNib() {
self.layer.cornerRadius = self.frame.height / 2
self.backgroundImage = UIImage()
self.backgroundColor = UIColor.white
self.tintColor = UIColor.white
self.layer.borderColor = UIColor.lightGray.cgColor
self.layer.borderWidth = 1.0
if let textField = self.value(forKey: "searchField") as? UITextField{
textField.borderStyle = .none
textField.backgroundColor = UIColor.white
}
}
}
但是当我在移动设备上运行应用程序时,它陷入了困境。
答案 0 :(得分:0)
不是从Nib唤醒,而是在布局子视图中添加与框架相关的代码
# for Cloud Functions use
def get_service():
import googleapiclient.discovery
return googleapiclient.discovery.build('cloudresourcemanager', 'v1', cache_discovery=False)
service = get_service()