關(guān)于UISearchBar在tableHeaderView的情況
self.tableView.tableHeaderView = self.searchBar;
- (UISearchBar *)searchBar {
if (_searchBar == nil)
{
_searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth-80, 40)];
_searchBar.placeholder = @"搜索";
_searchBar.searchBarStyle = 0;
_searchBar.delegate = self;
// 邊框顏色
_searchBar.backgroundImage = [self createImageWithColor:kRGBA(242, 242, 242, 1)];
UITextField *searchField = [_searchBar valueForKey:@"searchField"];
if (searchField) {
[searchField setBackgroundColor:[UIColor whiteColor]];
[searchField setValue:kGrayColor forKeyPath:@"_placeholderLabel.textColor"];
// 修正光標(biāo)顏色
[searchField setTintColor:kGrayColor];
}
}
return _searchBar;
}
#pragma mark - 根據(jù)顏色獲取圖片
- (UIImage *)createImageWithColor:(UIColor *)color
{
//圖片尺寸
CGRect rect = CGRectMake(0, 0, 10, 10);
//填充畫筆
UIGraphicsBeginImageContext(rect.size);
//根據(jù)所傳顏色繪制
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
//顯示區(qū)域
CGContextFillRect(context, rect);
// 得到圖片信息
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
//消除畫筆
UIGraphicsEndImageContext();
return image;
}
代理方法
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
//隱藏取消按鈕
searchBar.showsCancelButton = NO;
return YES;
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
// 當(dāng)text改變 就會(huì)調(diào)用
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。