美文网首页
UISearch没有文字下搜索按钮也可点击

UISearch没有文字下搜索按钮也可点击

作者: sjaljlajslkf | 来源:发表于2018-04-16 14:05 被阅读10次

UISearch没有文字下搜索按钮也可点击

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(50, 100, 200, 30)];
    searchBar.placeholder = @"清新时尚色";
    UITextField *searchBarTextField = nil;
    NSArray *views = ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0) ? searchBar.subviews : [[searchBar.subviews objectAtIndex:0] subviews];
    for (UIView *subview in views)
    {
        if ([subview isKindOfClass:[UITextField class]])
        {
            searchBarTextField = (UITextField *)subview;
            break;
        }
    }
  //重点在于这个属性
    searchBarTextField.enablesReturnKeyAutomatically = NO;
    [self.view addSubview:searchBar];

相关文章

网友评论

      本文标题:UISearch没有文字下搜索按钮也可点击

      本文链接:https://www.haomeiwen.com/subject/rdqekftx.html