【转】UISearchController change 'Cancel' button title

http://stackoverflow.com/questions/28642807/uisearchcontroller-change-cancel-button-title

swift version:

for view:UIView in (searchView?.subviews)!
{
for subView:UIView in (view.subviews)
{
if ( subView is UIButton )
{
let cancelBut = subView as! UIButton

            //do stuff with cancelButton here
        }
    }
}

You can change the "Cancel" Button in search bar using this-

for (UIView *view in searchBar.subviews)
{
for (id subview in view.subviews)
{
if ( [subview isKindOfClass:[UIButton class]] )
{
[subview setEnabled:YES];
UIButton cancelButton = (UIButton)subview;
[cancelButton setTitle:@"hi" forState:UIControlStateNormal];

        NSLog(@"enableCancelButton");
        return;
    }
}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • ViewsBecause view objects are the main way your applicati...
    梁光飞阅读 671评论 0 0
  • //设置尺寸为屏幕尺寸的时候self.window = [[UIWindow alloc] initWithFra...
    LuckTime阅读 850评论 0 0
  • 1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现cl...
    以德扶人阅读 2,566评论 2 50
  • // //UIView.h //UIKit // //Copyright (c) 2005-2015 Apple ...
    李某lkb阅读 1,761评论 0 0
  • 周晨(大发化纤有限公司) 276期,感谢1组成员 【日精进打卡第39天】 【知~学习】 《六项精进》读1遍 共75...
    周晨i阅读 290评论 0 0