是否可以在iPad的uisearchbar中添加像野生动物园一样的刷新徽标?
像下面的图片吗?

我有一个uisearchbarcontroller和uitableview。想知道是否有可能像刷新一样添加箭头。可以添加搜索结果和书签。

谢谢。

最佳答案

是的,您可以..您将需要用自定义按钮替换清除按钮,以进行刷新操作..这是执行此操作的代码

UISearchBar *searchBar = yourSearchBar;
UITextField *searchtextfield = [searchBar.subviews objectAtIndex:1];
UIButton *cButton = [UIButton buttonWithType:UIButtonTypeCustom];
cButton.frame = CGRectMake(0, 0, 20 , 20);
cButton.backgroundColor = [UIColor clearColor];
[cButton setImage:[UIImage newImageFromResource:@"yourButtonImage"] forState:UIControlStateNormal];//refresh image.
cButton.contentMode = UIViewContentModeScaleToFill;
[cButton addTarget:self action:@selector(refreshButtonPressed) forControlEvents:UIControlEventTouchUpInside];//This is the custom event(refresh)
[searchtextfield setRightView:cButton];
[searchtextfield setRightViewMode:UITextFieldViewModeAlways];

请享用 :)

关于ios - 向uisearchbar添加刷新徽标,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9324077/

10-12 00:15