清除UISearchBar的文本框背景

 UIImage *searchImg = [UIImage imageNamed:@"seach_top_bk"];
    searchImg=[searchImg resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20) resizingMode:UIImageResizingModeStretch];//拉伸背景图片
    
    _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(115, 7,200 , 30)];
    _searchBar.backgroundImage =searchImg;// 背景图片
    _searchBar.delegate = self;
    _searchBar.showsCancelButton = NO;
    _searchBar.placeholder = @"输入关键字..";
    
    for (UIView * subView in _searchBar.subviews) {
        if ([subView isKindOfClass:[UITextField class]]) {
            UITextField * field = (UITextField *) subView;
            field.borderStyle = UITextBorderStyleNone;
            field.background = nil; //将UISearchBar的UITextField的背景清除掉
        }
    }

 

posted @ 2013-04-11 10:27  Dadada胖纸er  阅读(257)  评论(0编辑  收藏  举报