如何更改iOS上的UISearchBar組件的內(nèi)部背景顏色
我們提供的服務有:成都網(wǎng)站制作、成都做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、蘇尼特左ssl等。為數(shù)千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術的蘇尼特左網(wǎng)站制作公司
1. 使用此代碼改變搜索欄“UITextField將backgroundImageUITextField *searchField;
NSUInteger numViews = [searchBar.subviews count];
for(int i = 0; i < numViews; i++) {
if([[searchBar.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) { //conform?
searchField = [searchBar.subviews objectAtIndex:i];
}
}
if(!(searchField == nil)) {
searchField.textColor = [UIColor whiteColor];
[searchField setBackground: [UIImage p_w_picpathNamed:@"yourImage"]];//just add here gray p_w_picpath which you display in quetion
[searchField setBorderStyle:UITextBorderStyleNone];
}
該波紋管代碼的變化UISearchBarIcon UIImageView *searchIcon = [[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:@"yourSearchBarIconImage"]];
searchIcon.frame = CGRectMake(10, 10, 24, 24);
[searchBar addSubview:searchIcon];
[searchIcon release];
也為改變searcBar圖標搜索欄的你哪些可用的iOS 5 +- (void)setImage:(UIImage *)iconImage forSearchBarIcon:(UISearchBarIcon)icon state:(UIControlState)state
在這里你可以設置4種UISearchBarIcon即UISearchBarIconBookmarkUISearchBarIconClearUISearchBarIconResultsListUISearchBarIconSearch我希望這可以幫助您...
2. 根據(jù)的UISearchBar 你這個函數(shù)適用于iOS 5.0 +。- (void)setSearchFieldBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state
用例:[mySearchBar setSearchFieldBackgroundImage:myImage forState:UIControlStateNormal];
可悲的是,在iOS 4的你需要恢復到較少見其他的答案。
3. 只是自定義文本字段本身。 我只是這樣做的,它工作正常(的iOS 7)。UITextField *txfSearchField = [_searchBar valueForKey:@"_searchField"];
txfSearchField.backgroundColor = [UIColor redColor];
這樣,您就不需要創(chuàng)建一個圖像,它的大小,等..
4. 對于只改變顏色:searchBar.tintColor = [UIColor redColor];
為應用背景圖像:[self.searchBar setSearchFieldBackgroundImage:
[UIImage p_w_picpathNamed:@"Searchbox.png"]
forState:UIControlStateNormal];
5. 私有API的:for (UIView* subview in [[self.searchBar.subviews lastObject] subviews]) {
if ([subview isKindOfClass:[UITextField class]]) {
UITextField *textField = (UITextField*)subview;
[textField setBackgroundColor:[UIColor redColor]];
}
}