ios - 向 uisearchbar 添加刷新 Logo

标签 ios xcode ipad

是否可以在 iPad 上的 uisearchbar 中添加类似 safari 中的刷新 Logo ? 喜欢下图吗?

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

refresh icon

谢谢。

最佳答案

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

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 添加刷新 Logo ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9324077/

相关文章:

ios - UIPageViewController (ScrollStyle) 不调用 dataSource 方法

iOS 13 NSAttributedString 在 UITableViewCell 内无法正常工作

ipad - 来自 UINavigationController 的弹出 View 多次导致应用程序崩溃

ios - 为什么这不在 UITableView 中显示信息?

ios - Xcode 中的代码签名 "Debug"或 "Release"有什么意义?

iphone - 如何删除UIImage的一部分

ios - iPad 2 确定设备颜色

objective-c - 根据另一个 NSArray 字符串的排序对自定义对象的 NSArray 进行排序

iphone - 返回 TabBar 主屏幕

ios - 圆角不适用于除 iPhone XS max 和 XR 以外的所有模拟器