美文网首页
UIKit之UISearchBar

UIKit之UISearchBar

作者: MI移动 | 来源:发表于2017-07-20 11:27 被阅读0次
    #import "TestController.h"
    
    @interface TestController ()<UISearchBarDelegate>
    @property(strong, nonatomic)UISearchBar *searchBar;
    @end
    
    @implementation TestController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
    }
    
    - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
        NSLog(@"执行取消搜索操作");
    }
    - (void)searchBarResultsListButtonClicked:(UISearchBar *)searchBar{
        NSLog(@"下拉按钮");
    }
    - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
        NSLog(@"开始键入");
        return YES;
    }
    
    #pragma mark - lazyload
    - (UISearchBar *)searchBar{
        if (!_searchBar) {
            _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 44, kScreenWidth, 40)];
            _searchBar.backgroundColor = [UIColor grayColor];
            [self.view addSubview:self.searchBar];
            
            // 设置代理
            _searchBar.delegate = self;
            // 占位符
            _searchBar.placeholder = @"请输入";
            // 设置风格
            _searchBar.barStyle = UIBarStyleDefault;
            _searchBar.searchBarStyle = UISearchBarStyleDefault;
            // 设置本身带的字体颜色
            _searchBar.tintColor = [UIColor yellowColor];
            // 设置是否透明
            _searchBar.translucent = YES;
            // 取消图标
            _searchBar.showsCancelButton = YES;
            // 图书图标
            _searchBar.showsBookmarkButton = YES;
            // 显示搜索结果按钮
            _searchBar.showsSearchResultsButton = YES;
            // 键盘类型
            _searchBar.keyboardType = UIKeyboardAppearanceDefault;
        }
        return _searchBar;
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:UIKit之UISearchBar

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