我想在UISearchBar中自定义以下内容,如果有可能的话,那么:
下图是使用SDK相同图标的两个第一个问题的示例。
提前致谢。
PD:请仅参考Swift。
答案 0 :(得分:0)
1)找到一个好的图标,你想要的颜色,并使用.setImage
设置它// images
self.setImage(UIImage(named: "Search-white"), forSearchBarIcon: UISearchBarIcon.Search, state: UIControlState.Normal)
3)对我来说,这使用递归函数来查找实际的文本字段。
extension UIView {
func recursive_applyTheme_Search(
#dynamicTextStyle: NSString,
bgColor: UIColor,
cursorColor: UIColor,
textColor: UIColor,
placeholderTextColor: UIColor,
borderColor: UIColor,
borderWidth: CGFloat,
cornerRadius: CGFloat) {
for subview in self.subviews
{
if subview is UITextField {
(subview as! UITextField).applyThemeForSearchBar(
dynamicTextStyle: dynamicTextStyle,
bgColor: bgColor,
cursorColor: cursorColor,
textColor: textColor,
placeholderTextColor: placeholderTextColor,
borderColor: borderColor,
borderWidth: borderWidth,
cornerRadius: cornerRadius)
}
else { subview.recursive_applyTheme_Search(
dynamicTextStyle: dynamicTextStyle,
bgColor: bgColor,
cursorColor: cursorColor,
textColor: textColor,
placeholderTextColor: placeholderTextColor,
borderColor: borderColor,
borderWidth: borderWidth,
cornerRadius: cornerRadius) }
}
}
}