UIsearchbar--搜索

UISearchBar *SearchBar = [[UISearchBar alloc] init];

SearchBar.frame = CGRectMake(10, -2, SCREENWIDTH-30,35);

SearchBar.placeholder = @"请输入搜索关键字";

SearchBar.backgroundColor = [UIColor clearColor];

SearchBar.searchBarStyle = UISearchBarStyleMinimal;

SearchBar.showsCancelButton = YES;//显示取消按钮

[SearchBar resignFirstResponder];// 设置为第一响应者

SearchBar.showsBookmarkButton = YES;//显示书本按钮

//修改书本图标

[SearchBar setImage:[UIImage imageNamed:@"search"]forSearchBarIcon:UISearchBarIconBookmark state:UIControlStateNormal];

//修改搜索输入文本的背景

[SearchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"searchinput"] forState:UIControlStateNormal];

//修改搜索输入框内左侧的指示图标

[SearchBar setImage:[UIImage imageNamed:@"search"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];

//改变提示文字颜色

UITextField *sbTextField = [SearchBar valueForKey:@"searchField"]; //首先取出textfield

//        sbTextField.textColor = [UIColor blueColor]; //输入的颜色

UILabel *sbPlaceholderLabel = [sbTextField valueForKey:@"placeholderLabel"]; //占位字段

sbPlaceholderLabel.textColor = RGBCOLOR(250,51, 181); //改变颜色

//修改取消按钮的字体颜色

UIButton *cancleBtn = [SearchBar valueForKey:@"cancelButton"];

//修改标题和标题颜色

[cancleBtn setTitle:@"取消" forState:UIControlStateNormal];

[cancleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

你可能感兴趣的:(UIsearchbar--搜索)