UISearchBar和UISearchDisplayController

来源:互联网 发布:美工是做什么的 编辑:程序博客网 时间:2024/05/29 03:15

记录下在使用UISearchBar和UISearchDisplayController中遇到的问题

1.在iPad上,当UISearchDisplayController active的时候,UISearchBar会向下移动。
参考此处:UISearchDisplay issue - move down
解决方法:

if([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]){    self.edgesForExtendedLayout = UIRectEdgeNone;}

2.在搜索的时候,影藏Cancel按钮
参考此处:Hide UISearchBar Cancel Button
解决方法:创建UISearchBar的一个子类,重写如下的方法

-(void)layoutSubviews{    [super layoutSubviews];    [self setShowsCancelButton:NO animated:NO];}

3.设置UISearchBar的背景为透明or无颜色
参考此处:UISearchBar clear background color or set background image [iphone sdk]
解决方法:

[searchBar setBackgroundImage:[UIImage new]];[searchBar setTranslucent:YES];

4.设置UISearchBar的背景颜色
参考此处:

  • How to change background color of UISearchBar in iOS7
  • [IOS] UISearchBar背景透明,去掉背景,自定义背景

解决方法:

searchBar.barTintColor = [UIColor redColor];

UISearchBar和UISearchDisplayController相关:

  • 官方的例子Simple UISearchBar with State Restoration
  • A simple tutorial of UISearchDisplayController (iOS 3-7)
  • iPhone Tutorial – UISearchDisplayController with NSPredicate
0 0
原创粉丝点击