自定义UISearchBar的背景图
生活随笔
收集整理的這篇文章主要介紹了
自定义UISearchBar的背景图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
可以重寫UISearchBar,然后調用layoutSubviews這個方法。| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | - (void)layoutSubviews { ????UITextField *searchField; ????NSUInteger numViews = [self.subviews count]; ????for(int i = 0; i < numViews; i++) { ????????if([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) { ????????????searchField = [self.subviews objectAtIndex:i]; ????????} ????} ????if(!(searchField == nil)) { ????????searchField.textColor = [UIColor whiteColor]; ????????[searchField.leftView setHidden:YES]; ????????[searchField setBackground: [UIImage imageNamed:@"SearchBarBackground.png"] ]; ????????[searchField setBorderStyle:UITextBorderStyleNone]; ????} ????? ????[super layoutSubviews]; } |
轉載于:https://www.cnblogs.com/ranger-jlu/p/3877925.html
總結
以上是生活随笔為你收集整理的自定义UISearchBar的背景图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 模拟TAB键
- 下一篇: .net利用程序集的GUID解决程序只能