更改搜索栏取消按钮的名称 IOS 7
Posted
技术标签:
【中文标题】更改搜索栏取消按钮的名称 IOS 7【英文标题】:change the name of the searchBar cancel button IOS 7 【发布时间】:2014-06-08 21:33:10 【问题描述】:我在更改搜索栏取消按钮的文本时遇到问题。
查看我的代码:
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
[_srBar setShowsCancelButton:YES animated:YES];
UIButton *cancelButton = nil;
for (UIView *subView in searchBar.subviews)
if ([subView isKindOfClass:NSClassFromString(@"UIButton")])
cancelButton = (UIButton*)subView;
[cancelButton setTitle:@"Annuller" forState:UIControlStateNormal];
我也已经尝试过其他选项
ios Change the title of cancel button in UISearchBar iOS - Customizing Cancel button of UISearchBar
在这个例子中我的代码没有调用方法
How to change the default text of Cancel Button which appears in the UISearchBar +iPhone
我的风景
#import <UIKit/UIKit.h>
@interface favorito : UIViewController<UISearchControllerDelegate, UISearchDisplayDelegate, UISearchBarDelegate,UITableViewDelegate,UITableViewDataSource>
@end
【问题讨论】:
【参考方案1】:id barButtonAppearanceInSearchBar = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
[barButtonAppearanceInSearchBar setBackgroundImage:grayBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[barButtonAppearanceInSearchBar setTitleTextAttributes:@
UITextAttributeFont : [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:20],
UITextAttributeTextColor : [UIColor blackColor]
forState:UIControlStateNormal];
[barButtonAppearanceInSearchBar setTitle:@"X"];
【讨论】:
以上是关于更改搜索栏取消按钮的名称 IOS 7的主要内容,如果未能解决你的问题,请参考以下文章
更改集合视图的 isHidden 属性不适用于搜索栏取消按钮