1
我想着這個UISearchBar,使它看起來與背景無縫(如在第二個圖像中)。是否有可能做到這一點?我已經嘗試在IB和編程設置,但沒有運氣。如何爲UISearchBar着色,使其看起來與背景無縫
感謝您的幫助
這裏有所需的外觀:
我想着這個UISearchBar,使它看起來與背景無縫(如在第二個圖像中)。是否有可能做到這一點?我已經嘗試在IB和編程設置,但沒有運氣。如何爲UISearchBar着色,使其看起來與背景無縫
感謝您的幫助
這裏有所需的外觀:
UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];
[searchField setBackground:[UIImage imageNamed:@"searchfield_bg"]];
[self.searchBar setTintColor:[UIColor blackColor]];
UIImage *searchimg = [UIImage imageNamed:@"search_panel.png"];
for (UIView *subview in self.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
UIView *bg = [[UIView alloc] initWithFrame:subview.frame];
bg.backgroundColor = [UIColor colorWithPatternImage:searchimg];
[self.searchBar insertSubview:bg aboveSubview:subview];
[subview removeFromSuperview];
[bg release];
break;
}
}
進出口使用這些圖片,你可以用你,改變顏色也一樣,我要求製作黑色搜索欄,以便使用黑色
,它會看起來像:
只是setTint顏色這樣的..
[searchBar setBarStyle:UIBarStyleDefault];
[searchBar setTintColor:[UIColor colorWithRed:.81 green:.14 blue:.19 alpha:1]];//set alpha with your requirement
也與圖像使用該代碼的工作很大..
for (UIView *subview in searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
UIView *bg = [[UIView alloc] initWithFrame:subview.frame];
bg.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top-bar.png"]];
[searchBar insertSubview:bg aboveSubview:subview];
[subview removeFromSuperview];
break;
}
}
而對於w與紅色孔搜索欄,然後簡單的複製粘貼此代碼伴侶..在這裏我解決這個問題
for (UIView *subview in searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
UIView *bg = [[UIView alloc] initWithFrame:subview.frame];
bg.backgroundColor = [UIColor redColor];
[searchBar insertSubview:bg aboveSubview:subview];
[subview removeFromSuperview];
break;
}
}
[searchBar setTintColor:[UIColor redColor]];
我已經試過了,但對我來說只是一個掩飾了粉紅色的色調顯示。 – hanumanDev
然後嘗試用colorWithRed:綠色:藍色隊友想我發佈它.. –
請,如果你有時間:) – hanumanDev