tableview前端基础设计(初级版)
tableView前端基础设计
实现的最终效果
操作目的:熟悉纯代码编辑TableView和常用的相关控件SearchBar、NavigationBar、TabBar等,以及布局和基本功能的实现。
一、TabBar编辑
TabBar(标签栏)为实现多视图呈现的控制器,因为控制视图呈现,所以要在app完成之前进行设置。学习链接
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. //创建window
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor=[UIColor clearColor]; //初始化一个tabBar
self.tb=[[UITabBarController alloc] init]; //设置为window的根控制器
self.window.rootViewController=self.tb;
self.tb.tabBar.backgroundColor=[UIColor whiteColor]; //设置状态栏的样式,控制不被navigationBar的颜色覆盖
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO]; //创建子控制器
[self MainLoadView];
[self.window makeKeyAndVisible];
return YES;
} -(void)MainLoadView{
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]]; TestViewController *c1=[[TestViewController alloc] init];
UINavigationController *nb1=[[UINavigationController alloc]initWithRootViewController:c1];
//wx.tabBarItem.title=@"message";
//wx.tabBarItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1];
c1.navigationItem.titleView=[self NavigationTitle:@"微信"]; contectViewController *c2=[[contectViewController alloc] init];
UINavigationController *nb2=[[UINavigationController alloc]initWithRootViewController:c2];
c2.navigationItem.titleView=[self NavigationTitle:@"通讯录"]; findViewController *c3=[[findViewController alloc] init];
UINavigationController *nb3=[[UINavigationController alloc]initWithRootViewController:c3];
c3.navigationItem.titleView=[self NavigationTitle:@"发现"]; meViewController *c4=[[meViewController alloc] init];
UINavigationController *nb4=[[UINavigationController alloc]initWithRootViewController:c4];
c4.navigationItem.titleView=[self NavigationTitle:@"我"]; self.tb.viewControllers=@[nb1,nb2,nb3,nb4];
[self customTabBar]; } -(UILabel *)NavigationTitle:(NSString *)TitleText{
UILabel *title=[[UILabel alloc] initWithFrame:CGRectMake(, , , )];
title.backgroundColor=[UIColor clearColor];
title.textColor=[UIColor whiteColor];
title.font=[UIFont boldSystemFontOfSize:];
title.textAlignment=UITextAlignmentCenter;
title.text=TitleText;
return title;
} //加载自定义的TabBarItem
-(void)customTabBar{
UITabBar *tabBar=self.tb.tabBar;
UITabBarItem *tabBarItem0 = [tabBar.items objectAtIndex:];
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:]; tabBarItem0.image = [[UIImage imageNamed:@"wechat-close.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem0.selectedImage = [[UIImage imageNamed:@"wechat-open.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem0.title=@"微信"; tabBarItem1.image = [[UIImage imageNamed:@"contact-close.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem1.selectedImage = [[UIImage imageNamed:@"contact-open.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem1.title=@"通讯录"; tabBarItem2.image = [[UIImage imageNamed:@"find-close.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem2.selectedImage = [[UIImage imageNamed:@"find-open.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem2.title=@"发现"; tabBarItem3.image = [[UIImage imageNamed:@"me-close.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem3.selectedImage = [[UIImage imageNamed:@"me-open.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem3.title=@"我"; [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
kUIColorFromRGB(0x7a7e83), NSForegroundColorAttributeName,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
kUIColorFromRGB(0x1aad19), NSForegroundColorAttributeName,
nil] forState:UIControlStateSelected];
}
二、搜索栏编辑
在ios8.0之前搜索栏是由SearchBar和SearchDisplayController联合控制呈现的,在ios8.0之后是由SearchController单独控制呈现。为了学习了解两种控制方式的区别,我在微信和通讯录页面用了两种不同的控制方式。最终体验就是改版后的省事多了,实现效果没有多大差别。(本测试中由于数据源格式不同所以呈现有些许差别)学习链接
改版前(关于SearchBar的部分代码,详情见demo)
@interface contectViewController ()<UISearchBarDelegate,UISearchDisplayDelegate>
@property (nonatomic,strong) UISearchBar *searchBar;
@property (nonatomic,strong) UISearchDisplayController *display;
@end @implementation contectViewController
- (void)viewDidLoad {
[self.searchBar setShowsScopeBar:NO];
[self search];
} -(void)search{
self.searchBar=[[UISearchBar alloc] init];
self.searchBar.placeholder=@"Search";
self.tableView.tableHeaderView = self.searchBar; self.display=[[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self]; self.searchBar.delegate=self;
self.display.searchResultsDataSource=self;
self.display.searchResultsDelegate=self;
self.display.delegate=self;
} //添加索引
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return self.titlearr; } -(NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
NSInteger count=;
for(NSString *character in self.titlearr){
if([[character uppercaseString] hasPrefix:title]){
return count;
}
count++;
}
return ;
} -(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(nullable NSString *)searchString{ NSPredicate *resultPredicate=[NSPredicate predicateWithFormat:@"self contains[cd] %@",searchString];
self.searcharr=[self.contect filteredArrayUsingPredicate:resultPredicate];
return YES;
}
@end
改版后(SearchBarController的相关代码)
@interface TestViewController ()
@property (nonatomic,strong) SearchResultViewController *mySRTVC;
@property (nonatomic,strong) UISearchController *svc; @end @implementation TestViewController
-(NSArray *)dataSource{
if(!_dataSource){
_dataSource=[User demoData];
}
return _dataSource;
}
- (void)viewDidLoad {
self.mySRTVC=[[SearchResultViewController alloc] init];
self.mySRTVC.mainSearchController = self;
self.svc=[[UISearchController alloc] initWithSearchResultsController:self.mySRTVC];
[self.svc.searchBar sizeToFit];
self.tableView.tableHeaderView=self.svc.searchBar; //设置搜索控制器的结果更新代理对象
self.svc.searchResultsUpdater=self; /* //Scope:就是效果图中那个分类选择器
self.svc.searchBar.scopeButtonTitles=@[@"设备",@"软件",@"其他"];
//为了响应scope改变时候,对选中的scope进行处理 需要设置search代理
self.svc.searchBar.delegate=self;
*/
self.definesPresentationContext=YES;
} #pragma mark - UISearchResultsUpdating /**实现更新代理*/
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
//获取到用户输入的数据
NSString *searchText=searchController.searchBar.text;
NSMutableArray *searchResult=[[NSMutableArray alloc]init];
for (User *u in self.dataSource) {
NSRange range=[u.name rangeOfString:searchText];
if(range.length> ){
[searchResult addObject:u];
}
}
self.mySRTVC.searchResults=searchResult; /**通知结果ViewController进行更新*/
[self.mySRTVC.tableView reloadData];
} #pragma mark - UISearchBarDelegate
/**点击按钮后,进行搜索页更新*/
-(void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
[self updateSearchResultsForSearchController:self.svc];
}
本版本的demo:GitHub链接
用SourceTree上传Xcode的代码到GitHub请参考=>这里
tableview前端基础设计(初级版)的更多相关文章
- 基础DP(初级版)
本文主要内容为基础DP,内容来源为<算法导论>,总结不易,转载请注明出处. 后续会更新出kuanbin关于基础DP的题目...... 动态规划: 动态规划用于子问题重叠的情况,即不同的子问 ...
- 前端基础之:JQuery(可编辑版)
前端基础之jquery 一 jQuery是什么? [1] jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多 javascript高手加入其team. [2] ...
- NSIS安装制作基础教程[初级篇], 献给对NSIS有兴趣的初学者
NSIS安装制作基础教程[初级篇], 献给对NSIS有兴趣的初学者 作者: raindy 来源:http://bbs.hanzify.org/index.php?showtopic=30029 时间: ...
- 前端基础面试题(JS部分)
1.几种基本数据类型?复杂数据类型?值类型和引用数据类型?堆栈数据结构? 基本数据类型:Undefined.Null.Boolean.Number.String 值类型:数值.布尔值.null.und ...
- 前端基础面试题(js部分)
前端基础面试题(JS部分) 1.几种基本数据类型?复杂数据类型?值类型和引用数据类型?堆栈数据结构? 基本数据类型:Undefined.Null.Boolean.Number.String值类 ...
- web前端基础知识及快速入门指南
web前端基础知识及快速入门指南 做前端开发有几个月了,虽然说是几个月,但是中间断断续续的上课.考试以及其它杂七杂八的事情,到现在居然一直感觉自己虽然很多前端的知识很眼熟,却也感觉自己貌似也知识在门口 ...
- Python之路,Day4 - Python基础4 (new版)
Python之路,Day4 - Python基础4 (new版) 本节内容 迭代器&生成器 装饰器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 ...
- 前后端分离之Web前端架构设计
架构设计:前后端分离之Web前端架构设计 在前面的文章里我谈到了前后端分离的一些看法,这个看法是从宏观的角度来思考的,没有具体的落地实现,今天我将延续上篇文章的主题,从纯前端的架构设计角度谈谈前后端分 ...
- html css 前端基础 学习方法及经验分享
前言: 入园第一天,想分享一点儿前端基础html css 的学习方法和一些经验给热爱前端,但是不知道从哪儿开始,依旧有些迷茫的新手朋友们.当然,适合每个人的学习方式不同,以下所讲的仅供参考. 一.关于 ...
随机推荐
- Oracle通用维、父子维相互转换
所谓通用维即维度层级1.2.3均作为字段展示为列,父子维即维度id+父级维度+维度层级字段 通用维 lvl_id1 lvl_name1 lvl_id2 lvl_name2 lvl_id3 lvl_na ...
- 图书馆管理系统(C语言)
/* 实现的功能 * @ 1. 录入图书的信息 * @ 2. 给定图书的编号,显示该图书的详细信息 * @ 3. 给定作者的姓名,可以显示该作者所有的书 * @ 4. 给定出版社,可以显示该出版社出版 ...
- Abp 中 模块 加载及类型自动注入 源码学习笔记
注意 互相关联多使用接口注册,所以可以 根据需要替换. 始于 Startup.cs 中的 通过 AddApplication 扩展方法添加 Abp支持 1 services.AddApplicati ...
- day21_python_1124
01 昨日内容回顾 类与类之间的关系: 依赖关系:将一个类的对象或者类名传到另一个类中. 关联关系 组合关系:将一个类的对象封装到另一个类的对象属性中. 聚合关系 boy gril school te ...
- perceptual loss
https://arxiv.org/abs/1603.08155 两个网络:image transfer网络和loss网络 image transfer网络: 将输入图片y通过映射f W (x)得到输 ...
- android LogConfigurator
android LogConfigurator 此为第三方的 Log日志
- apex透视自瞄无后子弹追踪飞天加速辅助
apex透视自瞄无后子弹追踪飞天加速辅助apex透视自瞄无后子弹追踪飞天加速辅助apex透视自瞄无后子弹追踪飞天加速辅助apex透视自瞄无后子弹追踪飞天加速辅助apex透视自瞄无后子弹追踪飞天加速辅助 ...
- 表单传值给@Controller
<form action="springmvc/testModelAttributes" method="post"> <input type ...
- Intellij idea配置及安装插件小记一二
1.项目创建慢及控制台乱码解决. -DarchetypeCatalog=internal:项目骨架采用内部,解决Maven项目创建生成慢: -Dfile.encoding=GB2312:控制台用Sys ...
- KendoUi 学习笔记一
本系列主要是记录KendoUI的学习过程. KendoUi的特点有以下特点: 1. 70+UI控件 控件有DataGrids,DropDowns,Menus和Buttons,还有一些商业的控件,比如C ...