custom UISearchBar

本文详细介绍了如何在iOS应用中实现一个自定义的UISearchBar,并将其与UITableView结合使用,提供高效的搜索功能。通过设置搜索栏样式、颜色、键盘类型等属性,使用户体验更加流畅。同时,展示了如何在UITableView头部添加搜索栏,方便用户快速筛选和查找所需内容。

直接添加:

ExpandedBlockStart.gif代码
UISearchBar *mySearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.00.0, self.view.bounds.size.width, 45)];
         mySearchBar.
delegate = self;
         mySearchBar.showsCancelButton 
= NO;
         mySearchBar.barStyle
=UIBarStyleDefault;
         mySearchBar.placeholder
=@"Enter Name or Categary";
         mySearchBar.tintColor = [UIColor colorWithRed:(247.0/255.0) green:(126.0/255) blue:(33.0/255) alpha:1.0];
         mySearchBar.keyboardType
=UIKeyboardTypeNamePhonePad;
         [self.view addSubview:mySearchBar];
         [mySearchBar release];

在tableview上添加:

ExpandedBlockStart.gif代码
//add Table
        UITableView *myBeaconsTableView = [[UITableView alloc] 
                                           initWithFrame:CGRectMake(
00, self.view.bounds.size.width, self.view.bounds.size.height-40
                                           style:UITableViewStylePlain];
        
        myBeaconsTableView.backgroundColor 
= [UIColor whiteColor];
        myBeaconsTableView.
delegate=self;
        myBeaconsTableView.dataSource
=self;
        [myBeaconsTableView setRowHeight:
40];
        
        
// Add searchbar 
        searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.00.0, self.view.bounds.size.width, 40)];
        searchBar.placeholder
=@"Enter Name";
        searchBar.
delegate = self;
        myBeaconsTableView.tableHeaderView 
= searchBar;
        searchBar.autocorrectionType 
= UITextAutocorrectionTypeNo;
        searchBar.autocapitalizationType 
= UITextAutocapitalizationTypeNone;
        [searchBar release];
        
        [self.view addSubview:myBeaconsTableView];
        [myBeaconsTableView release];


 

转载于:https://www.cnblogs.com/fairycao/archive/2010/04/06/1705213.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值