【问题标题】:change the name of the searchBar cancel button IOS 7更改搜索栏取消按钮的名称 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

【问题讨论】:

    标签: ios uiviewcontroller uibutton uisearchbar


    【解决方案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"];
    

    【讨论】:

      猜你喜欢
      • 2014-02-09
      • 1970-01-01
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 2017-04-05
      • 2013-09-30
      相关资源
      最近更新 更多