我正在尝试像这样自定义我的搜索栏
到目前为止,我已经设法做到这一点
现在我需要知道如何在右侧添加图像,塑造角落和改变图像的背景。到目前为止,这是我的代码。我可以在 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];
}
}