自從接觸iOS快一年多的時(shí)間了,感覺(jué)自己還是菜鳥一枚,最近在整理自己的開發(fā)過(guò)程中得點(diǎn)點(diǎn)滴滴,想通過(guò)博客的形式記錄下來(lái)。本博客會(huì)陸續(xù)添加內(nèi)容,鑒于本人水平有限,如有錯(cuò)誤,請(qǐng)給與指正,感激不盡。
“真誠(chéng)服務(wù),讓網(wǎng)絡(luò)創(chuàng)造價(jià)值”是我們的服務(wù)理念,創(chuàng)新互聯(lián)公司團(tuán)隊(duì)十年如一日始終堅(jiān)持在網(wǎng)站建設(shè)領(lǐng)域,為客戶提供優(yōu)質(zhì)服。不管你處于什么行業(yè),助你輕松跨入“互聯(lián)網(wǎng)+”時(shí)代,PC網(wǎng)站+手機(jī)網(wǎng)站+公眾號(hào)+小程序設(shè)計(jì)。修改UISearchBar的樣式,網(wǎng)上也有很多種,也都大同小異,本篇也不例外,但確實(shí)很實(shí)用,廢話不多說(shuō),上代碼:
1.UISearchBar帶有背景顏色的
if (!_searchBar) {
_searchBar=[[UISearchBar alloc]initWithFrame:CGRectMake(10, 20, self.view.frame.size.width-20, 40)];
_searchBar.placeholder=@"搜索";
_searchBar.delegate=self;
//searchBar的背景顏色
//1.
[_searchBar setBackgroundColor:[UIColor orangeColor]];
//2.關(guān)鍵
[[[_searchBar.subviews objectAtIndex:0].subviews objectAtIndex:0] removeFromSuperview];
//顯示取消按鈕
_searchBar.showsCancelButton=YES;
UIButton *cancelBtn=[_searchBar valueForKey:@"_cancelButton"];
[cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
cancelBtn.titleLabel.font=[UIFont systemFontOfSize:14];
[cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//設(shè)置光標(biāo)的顏色
_searchBar.tintColor=[UIColor redColor];
UITextField *searchFiled=[_searchBar valueForKey:@"_searchField"];
//設(shè)置處于編輯狀態(tài)
[searchFiled becomeFirstResponder];
//輸入文本的顏色
searchFiled.textColor=[UIColor greenColor];
//輸入文本字體的大小
searchFiled.font=[UIFont systemFontOfSize:14];
//輸入框的圓角設(shè)置
searchFiled.layer.cornerRadius=10;
searchFiled.layer.masksToBounds=YES;
//輸入框里面的背景顏色
searchFiled.backgroundColor=[UIColor whiteColor];
//提示文本的顏色
[searchFiled setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
self.cancelField=searchFiled;
//輸入框里的圖標(biāo)
[_searchBar setImage:[UIImage p_w_picpathNamed:@"boy.jpg"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
[self.view addSubview:_searchBar]
2.UISearchBar不帶背景顏色的
// 如果不要searchBar的背景顏色
// 1.關(guān)鍵
[_searchBar setBackgroundColor:[UIColor clearColor]];
[[[_searchBar.subviews objectAtIndex:0].subviews objectAtIndex:0] removeFromSuperview];
// 2.
UIView *searchView=[[UIView alloc]initWithFrame:CGRectMake(10, 20, self.view.frame.size.width-20, 40)];
searchView.layer.cornerRadius=10;
searchView.layer.borderColor=[UIColor orangeColor].CGColor;
searchView.layer.borderWidth=1.f;
[self.view addSubview:searchView];
[self.view addSubview:_searchBar];
#pragram--
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSLog(@"實(shí)時(shí)監(jiān)控文字輸入");
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
NSLog(@"點(diǎn)擊搜索按鈕");
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
NSLog(@"點(diǎn)擊取消按鈕");
[self.cancelField resignFirstResponder];
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。