我試圖做一個UISearchBar
矩形,而不是圓形的,但所有的解決方案,我發現迄今(主要是通過迭代子視圖)似乎在iOS 7破矩形的UISearchBar在iOS 7
我做了一些研究自己事實證明,它只有一個UIView
子視圖,其中有子視圖,UISearchBarBackground
和UISearchBarTextField
(它們都是私有類)。 我試圖
if ([view isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[view removeFromSuperview];
}
和
if ([view conformsToProtocol:@protocol(UITextInputTraits)]) {
@try {
[(UITextField *)view setBorderStyle:UITextBorderStyleRoundedRect];
}
@catch (NSException * e) {
// ignore exception
}
}
其中view
是一個UIView
子視圖的子視圖,但沒有人似乎工作。
事實證明,問題部分原因是我將UISearchBar的搜索樣式(在IB中)設置爲最小。如果你將它設置爲Prominent,那麼第一段代碼就可以工作。 (實際上,它仍然是圓形的,所以不是完美的解決方案。如果有人有更好的想法,請分享它。) – Rickye
您可能想要將其作爲答案發布。 – Marco
@Marco看到我對該評論的編輯,這不是最好的解決方案,但是如果沒有人在一段時間內提出更好的解決方案,我會發布它。 – Rickye