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

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没有文字下搜索按钮也可点击)