【学习ios之路:UI系列】(UISearchBar,UISearchDisplayController) 和UISearchController(iOS8新特性)

1.UISearchBar(效果如下:)


①创建UISearchBar对象

   //初始化,定义frame
    UISearchBar *bar = [[UISearchBar alloc] initWithFrame:CGRectMake
                                            (0, 50, self.view.frame.size.width, 80)];
    //添加到控制器的视图上 
    [self.view addSubview:bar];
②UISerachBar的属性

   //autocapitalizationType:包含4种类型,但是有时候键盘会屏蔽此属.
  //1.autocapitalizationType————自动对输入文本对象进行大小写设置.
    bar.autocapitalizationType = UITextAutocapitalizationTypeWords;
  //2.autocorrectionType————自动对输入文本对象进行纠错 
   bar.autocorrectionType = UITextAutocorrectionTypeYes; 
  //3.设置title
   bar.prompt = @"全部联系人"; 

   //4.设置颜色 
   bar.tintColor  = [UIColor purpleColor];//渲染颜色
   bar.barTintColor = [UIColor orangeColor];//搜索条颜色
   bar.backgroundColor =  [UIColor purpleColor];//背景颜色,因为毛玻璃效果(transulent).

   //5.translucent————指定控件是否会有透视效果
   bar.translucent = YES; 

   //6.scopeButtonTitles(范围buttonTitle)
    bar.scopeButtonTitles = @[@"精确搜索",@"模糊搜索"];
    bar.selectedScopeButtonIndex = 1;//通过下标指定默认选择的那个选择栏

   //7.控制搜索栏下部的选择栏是否显示出来(需设置为YES 才能使用scopebar)
    bar.showScopeBar = YES;

   //8.设置搜索栏右边的按钮
    bar.showsSearchResultsButton  = YES;//向下的箭头
    bar.showsCancelButton = YES; //取消按钮
    bar.showsBookmarkButton =  YES; //书签按钮

    //9.提示内容
    bar.placeholder = @"搜索";

    //10.取消键盘操作
   [searchBar resignFirstResponder]; 

   //11.设置代理
   //UISearchBar不执行搜索行为,必须使用delegate,当输入搜索文本、点击button按钮后,代理的方法
    会完成搜索对应的操作。
   //.控件的委托,委托要遵从UISearchBarDelegate协议,默认是nil
   bar.delegate = s
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值