我想定製我的搜索欄這樣 定製UISearch酒吧
到目前爲止,我已經成功地做到高達這個
現在我需要知道如何在右側添加圖像,塑造角落並將背景變爲圖像。這是我的代碼到目前爲止。我可以在UITextField的幫助下做到這一點,但我想使用UISearchBar來做到這一點。任何幫助?
- (void)setSearchIconToFavicon
{
// commented are the things I tried out
UITextField *searchField = nil;
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:[UITextField class]])
{
searchField = (UITextField *)subview;
break;
}
}
if (searchField)
{
UIImage *image = [UIImage imageNamed: @"search_btn.png"];
UIImageView *iView = [[UIImageView alloc] initWithImage:image];
//UIImage *image2 = [UIImage imageNamed: @"search_next_btn.png"];
//UIImageView *iView2 = [[UIImageView alloc] initWithImage:image2];
searchField.leftView = iView;
//searchField.rightView=iView2;
[[self.searchBar.subviews objectAtIndex:0] removeFromSuperview];
searchField.textColor = [UIColor grayColor];
}
}
沒有工作,圖像沒有出現。 – Gamerlegend
你試過什麼?你有沒有定製搜索欄? –
我試過在我的問題中加入了我的代碼,但沒有迴應 – Gamerlegend