UISearchBar

//修改UISearchBar取消按钮颜色
    [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:[NSArray arrayWithObjects:[UISearchBar class], nil]] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor greenColor] forKey:NSForegroundColorAttributeName] forState:UIControlStateNormal];
    
    UISearchBar * searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 6.0f, UI_SCREEN_WIDTH ,64.0f )];
    searchBar.delegate = self;
    searchBar.barStyle = UIBarStyleBlackTranslucent;
    searchBar.backgroundColor = [UIColor clearColor];
    searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
    searchBar.showsCancelButton = YES;
    searchBar.placeholder = @"搜索";
//    searchBar.tintColor = [UIColor clearColor];//COLOR_HEX(0x9A8316)
    searchBar.keyboardType =  UIKeyboardTypeDefault;
    searchBar.returnKeyType = UIReturnKeySearch;
    [searchBar setSearchFieldBackgroundImage:[IMG(@"input_discovery_search.png") resizableImageWithCapInsets:UIEdgeInsetsMake(10.0f, 20.0f, 10.0f, 20.0f) resizingMode:UIImageResizingModeStretch] forState:UIControlStateNormal];
    [searchBar setImage:IMG(@"icon_discovery_search.png") forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
    [searchBar setImage:IMG(@"icon_search_cancle.png") forSearchBarIcon:UISearchBarIconClear state:UIControlStateNormal];

你可能感兴趣的:(iOS基础)