搜索栏+collectionView实现
效果图如下:

@property (nonatomic,weak) BaseViewController *parentController;
- (instancetype)initWithParentControler:(BaseViewController *)controller;
- (void)prepareView;
@end
{
if (self = [superinit]) {
_parentController = controller;
}
returnself;
}
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
self.backgroundColor = NF_Color_C20;
_page = 1;
_gameRoomDataArray = [NSMutableArrayarray];
_sessionArray = [NSMutableArrayarray];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayoutalloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
layout.sectionInset = UIEdgeInsetsMake(10, 9, 15, 9);
layout.minimumInteritemSpacing = 9;
layout.minimumLineSpacing = 9;
self.gameRoomCollectionView = [[UICollectionViewalloc]initWithFrame:CGRectMake(0, 44+20, SCREEN_WIDTH, SCREEN_HEIGHT-44-20) collectionViewLayout:layout];
self.gameRoomCollectionView.delegate = self;
self.gameRoomCollectionView.dataSource = self;
self.gameRoomCollectionView.backgroundColor = NF_Color_C16;
[self.gameRoomCollectionViewregisterClass:[IDSGameRoomHomePageChangeCellclass] forCellWithReuseIdentifier:@"THEcellid"];
self.gameRoomCollectionView.showsVerticalScrollIndicator = NO;
self.gameRoomCollectionView.showsHorizontalScrollIndicator = NO;
MJRefreshFooter *footer = [IDSRefreshfooterWithRefreshingTarget:selfrefreshingAction:@selector(footerVoid)];
_gameRoomCollectionView.mj_footer = footer;
self.gameRoomCollectionView.mj_footer.hidden = YES;
[selfaddSubview:_gameRoomCollectionView];
[selfaddSearchBar];
[_parentController.viewaddSubview:self];
}
if (!self.searchBar) {
self.searchBarBoundsY = 20;
self.searchBar = [[UISearchBaralloc]initWithFrame:CGRectMake(0,self.searchBarBoundsY, [UIScreenmainScreen].bounds.size.width, 44)];
self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
self.searchBar.tintColor = NF_Color_C27;
self.searchBar.barTintColor = NF_Color_C1;
self.searchBar.delegate = self;
self.searchBar.placeholder = @"搜索房号/房间名";
[self.searchBarsetAutocorrectionType:UITextAutocorrectionTypeNo];
[self.searchBarsetAutocapitalizationType:UITextAutocapitalizationTypeNone];
[[UITextFieldappearanceWhenContainedIn:[UISearchBarclass], nil] setTextColor:[UIColorblackColor]];
}
if (![self.searchBarisDescendantOfView:self]) {
[selfaddSubview:self.searchBar];
}
[self.searchBarsetShowsCancelButton:YESanimated:NO];
[self.searchBarbecomeFirstResponder];
if (![_queryNoticeTimerisValid]) {
[selfstartQueryTimer];
}
}
{
[self.searchBarsetShowsCancelButton:YESanimated:NO];
[self.searchBarresignFirstResponder]; //searchBar失去焦点
UIButton *cancelBtn = [self.searchBarvalueForKey:@"cancelButton"]; //首先取出cancelBtn
cancelBtn.enabled = YES; //把enabled设置为yes
}
{
[selfhiddenKeyBoard];
}
{
for (UIView *oneView inself.subviews) {
[oneView removeFromSuperview];
}
}
- (void)removeView
{
[selfremoveAllSubviews];
[selfremoveFromSuperview];
}
[selfstopQueryTimer];
if (searchText.length>0) {
self.searchBarActive = YES;
_searchWord = searchText;
[selfstartQueryTimer];
[self.gameRoomCollectionViewreloadData];
}else{
self.searchBarActive = NO;
[selfremoveEmptyView];
[self.gameRoomDataArrayremoveAllObjects];
[self.gameRoomCollectionViewreloadData];
}
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
[selfcancelSearching];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[selfhiddenKeyBoard];
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
[self.searchBarsetShowsCancelButton:YESanimated:YES];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
[selfhiddenKeyBoard];
[selfdataRequest];
}
-(void)cancelSearching{
[selfremoveView];
}
{
IDSLOG(@"IDSGameRoomSearchPage Dealloc.");
[selfreleaseSelf];
}
- (void)releaseSelf
{
self.gameRoomCollectionView.delegate = nil;
self.gameRoomCollectionView.dataSource = nil;
_gameRoomCollectionView = nil;
self.searchBar = nil;
[selfstopQueryTimer];
}
{
[selfstopQueryTimer];
if (nil == _queryNoticeTimer) {
_queryNoticeTimer = [NSTimerscheduledTimerWithTimeInterval:sIntervalTime
target:self
selector:@selector(dataRequest)
userInfo:nilrepeats:NO];
}
}
- (void)stopQueryTimer
{
if (self.queryNoticeTimer) {
[self.queryNoticeTimerinvalidate];
_queryNoticeTimer = nil;
}
}
{
if (!label.text.length) {
return;
}
NSMutableAttributedString *attributedString = [[NSMutableAttributedStringalloc] initWithString:label.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStylealloc] init];
[paragraphStyle setLineSpacing:spacing];
[attributedString addAttribute:NSParagraphStyleAttributeNamevalue:paragraphStyle range:NSMakeRange(0, [label.textlength])];
if (_searchWord) {
NSRange redRange = [[ [attributedString string] lowercaseString] rangeOfString:[_searchWordlowercaseString]];
if (redRange.length <= [label.textlength]) {
[attributedString setAttributes:@{NSForegroundColorAttributeName:NF_Color_C19,NSFontAttributeName:[UIFontsystemFontOfSize:Near_Final_Font_T9]}range:redRange];
}
}
[label setAttributedText:attributedString];
label.lineBreakMode = NSLineBreakByCharWrapping;
[label sizeToFit];
}
搜索栏+collectionView实现的更多相关文章
- 用collectionview实现瀑布流-转(后面附demo,供参考)
算法总体思路 先说一下总体上的思路.既然图片的大小.位置各不一样,我们很自然地会想到需要算出每个item的frame,然后把这些frame赋值给当前item的UICollectionViewLayou ...
- CollectionView水平和竖直瀑布流的实现
最近在项目中需要实现一个水平的瀑布流(即每个Cell的高度是固定的,但是长度是不固定的),因为需要重写系统 UICollectionViewLayout中的一些方法通过计算去实现手动布局,所以本着代码 ...
- tableViewCell嵌套collectionView,动态高度
方法有很多,有通过内容高度,经过代理回调,刷新的,甚至还有计算cell个数,然后根据cell大小计算的,这里推荐iOS 8新特性,通过AutoLayout,利用内容将cell撑起来; 关键代码: vi ...
- iOS开发之窥探UICollectionViewController(二) --详解CollectionView各种回调
UICollectionView的布局是可以自己定义的,在这篇博客中先在上篇博客的基础上进行扩充,我们先使用UICollectionViewFlowLayout,然后好好的介绍一下UICollecti ...
- WPF CollectionViewSource CollectionView
CollectionView 通俗讲就是可以对你绑定的集合可以进行 分组,排序 等功能 CollectionViewSource 根据字面意思是xxx的数据源 详细的介绍还是看 http://www ...
- ios中自定义tableView,CollectionView的cell什么时候用nib加载,什么时候用标识重用
做了一段时间的iOS,在菜鸟的路上还有很长的路要走,把遇到的问题记下来,好记性不如烂笔头. 在项目开发中大家经常会用到tableView和collectionView两个控件,然而在cell的自定义上 ...
- collectionview cell吸顶效果
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Hiragino Sans GB"; color: #cf8724 } ...
- collectionview使用
创建UICollectionViewFlowLayout 对象来设置相关的布局,包括itemSize,headerReferenceSize,sectionInset.设置对应的布局大小,相关的和顶部 ...
- collectionView
// /* UICollectionView 类是iOS6 新引进的API,用于展示集合视图, 布局更加灵活,可实现多列布局,用法类似于UITableView类. - 更新视图: [collectio ...
随机推荐
- WindowsService - 开发遇到的问题
1.Windows服务安装 通过cmd运行指令安装Windows服务: 安装方法:运行cmd,以InstallUtil.exe 来运行 Windows服务程序. 如果是Release模式的话,直接在c ...
- QT调用VC DLL的例子(所有源码)
http://blog.csdn.net/zhuce0001/article/details/20651025 http://blog.csdn.net/zhuce0001/article/detai ...
- WPF依赖属性(续)(1)
原文:WPF依赖属性(续)(1) 之前有写过几篇文章,详细地介绍了依赖属性的基本使用方法,如果你不想了解其内部实现机制的话,那么通过那两篇文章的介绍,足以应付平时的应用 ...
- 概率论经典问题 —— 三个事件 A、B、C 独立 ≠ 三个事件两两独立
三个事件 A.B.C 相互独立?三个事件两两独立? A:第一次正面朝上: B:第二次正面朝上: C:第一次和第二次结果不同: P(AB)=P(A)P(B): P(AC)=1/4=P(A)P(C)(不是 ...
- 【原】对MYSQL下视图的一些总结
注:本文使用mysql5.5版本为例. 做过数据库开发的同学,对视图(VIEW)应该不会陌生. 我接触视图最多的应用场景有两个: 1)出于权限问题,为了限制访问者看到过多的表字段(或内容),就 ...
- C#实现万年历(农历、节气、节日、星座、星宿、属相、生肖、闰年月、时辰)
C# 万年历 农历 节气 节日 星座 星宿 属相 生肖 闰年月 时辰地址:http://www.cnblogs.com/txw1958/archive/2013/01/27/csharp-calend ...
- hadoop学习笔记(四)——eclipse+maven+hadoop2.5.2源代码
Eclipse同maven进口hadoop源代码 1) 安装和配置maven环境变量 M2_HOME: D:\profession\hadoop\apache-maven-3.3.3 PATH: % ...
- Jenkins 部署
1 修改jenkins的根目录,默认地在C:\Documents and Settings\AAA\.jenkins . .jenkins ├─jobs│ └─JavaHelloWorld│ ...
- error: stable identifier required, but $iwC.this.$VAL4.sqlContext found.
在spark_shell创建SQLContext导入对象后sqlContext时间,例如,下面的例外: 找个理由sqlContext必须是val类型. 后引入到正常的变化. 版权声明:本文博客原创文章 ...
- 通通WPF随笔(1)——基于lucene.NET让ComboBox拥有强大的下拉联想功能
原文:通通WPF随笔(1)--基于lucene.NET让ComboBox拥有强大的下拉联想功能 我一直很疑惑百度.谷哥搜索框的下拉联想功能是怎么实现的?是不断地查询数据库吗?其实到现在我也不知道,他们 ...