if (isIOS7) { mySearchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)]; mySearchBar.autocorrectionType = UITextAutocorrectionTypeNo; mySearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone; mySearchBar.keyboardType = UIKeyboardTypeDefault; mySearchBar.placeholder = @"全国地区(中文/拼音/区号/别名) "; mySearchBar.delegate =self; mySearchBar.tag = 100; mySearchBar.showsCancelButton =NO;//是否显示取消按钮 [mySearchBar setBackgroundColor:MF_ColorFromRGB(229, 229, 229)]; [[[[mySearchBar.subviews objectAtIndex:0] subviews] objectAtIndex:0] removeFromSuperview]; // 去掉搜索框背景 [[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:MF_ColorFromRGB(181, 181, 181)]; // 修改placeholder textColor [self.view addSubview:mySearchBar]; } else { mySearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 2, 320, 40)]; mySearchBar.delegate = self; mySearchBar.autocorrectionType = UITextAutocorrectionTypeNo; mySearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone; mySearchBar.placeholder = @"全国地区(中文/拼音/区号/别名)"; mySearchBar.keyboardType = UIKeyboardTypeDefault; [mySearchBar setTranslucent:YES]; mySearchBar.backgroundColor = MF_ColorFromRGB(229, 229, 229); [[mySearchBar.subviews objectAtIndex:0]removeFromSuperview]; // 去掉搜索框背景 [[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:MF_ColorFromRGB(181, 181, 181)]; // 修改placeholder textColor [self.view addSubview:mySearchBar]; // 替换UITextField背景图 UITextField* searchField = nil; for (UIView* subview in mySearchBar.subviews) { if ([subview isKindOfClass:[UITextField class]]) { searchField = (UITextField*)subview; break; } } searchField.background = [MF_PngWithSkin(DEFAULTS_SKIN, @"search_Bar_bgImg.png") stretchableImageWithLeftCapWidth:30 topCapHeight:30]; }