? UISearchBar上有兩個(gè)組件UISearchBarBackground和UISearchBarTextField幌衣,通過遍歷實(shí)現(xiàn)自定義
? ?UISearchBar *searchBar = [[UISearchBar alloc] init];
? ? searchBar.delegate=self;
? ? searchBar.tintColor = [UIColor clearColor];
? ? searchBar.barTintColor = [UIColor clearColor];
? ? searchBar.delegate=self;
? ? searchBar.frame=CGRectMake(0,0,ScreenWidth-30,30);
? ? searchBar.placeholder=@"請(qǐng)輸入搜索關(guān)鍵詞";
? ? UITextField*searchTextField =nil;
????? for(UIView* subView in searchBar.subviews) {
? ? ? ? subView.backgroundColor = [UIColor clearColor];
? ? ? ? for(UIView* ssubViewinsubView.subviews) {
? ? ? ? ? ? NSString* className =NSStringFromClass([ssubView class]);
? ? ? ? ? ? if([classNameisEqualToString:@"UISearchBarBackground"]) {//UISearchBarBackground
? ? ? ? ? ? ? ? ssubView.backgroundColor = [UIColor clearColor];
? ? ? ? ? ? ? ? ssubView.tintColor= [UIColor clearColor];
? ? ? ? ? ? ? ? [ssubView removeFromSuperview];
? ? ? ? ? ? }else? if([classNameisEqualToString:@"UISearchBarTextField"]) {//UISearchBarTextField
? ? ? ? ? ? ? ? searchTextField = (UITextField*)ssubView;
? ? ? ? ? ? }
? ? ? ? }
? ? }
? ? searchBar.layer.borderColor = [UIColor clearColor].CGColor;
? ? searchBar.layer.masksToBounds=YES;
//設(shè)置搜索(放大鏡)圖標(biāo)
????[searchBarsetImage:[UIImage imageNamed:@"ASTTaxMap.bundle/AST_TaxMap_searchwhite"]
?? ? ? forSearchBarIcon:UISearchBarIconSearch
? ? ? ? ? ? ? ? ? state:UIControlStateNormal];
//光標(biāo)樣式
searchTextField = [[[searchBar.subviews firstObject]subviews]lastObject];
? ? searchTextField.textColor= [UIColor whiteColor];
? ? searchTextField.tintColor= [UIColor whiteColor];
? ? [searchTextField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
? ? searchTextField.font = [ASFont fontWithSize:ASFontNumber14];
? ? [titleView addSubview:searchBar];