[关闭]
@FoxBabe 2014-09-25T09:06:19.000000Z 字数 9596 阅读 4354

iOS代码库

代码库 iOS 控件



说明

版本信息

创建iOS代码库目的

iOS代码库简介

代码库简介

TTILibrary
- Category (常用扩展)
- Helper (常用工具类)
- Macro (公共宏和第三方参数宏)
- NetWork(网络相关操作)
- UI(常用控件)
iOSCodeProject (项目名称,可根据实际进行修改)
- Resource (项目中常用资源)
- Depend (常用依赖库)
- Models (对象数据)
- Views (项目中共用控件)
- Controlers (项目中的控制器层)


UI控件类

列表下拉刷新和上拉加载更多

使用PullingRefreshTableView实现上下拉动和分页效果,基本使用:

  1. //创建列表
  2. self.pullTable = [[PullingRefreshTableView alloc] init];
  3. self.pullTable.frame = self.view.bounds;
  4. self.pullTable.delegate=self;
  5. self.pullTable.dataSource = self;
  6. self.pullTable.pullingDelegate = self;
  7. self.pullTable.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleBottomMargin;
  8. [self.view addSubview:self.pullTable];
  9. //设置委托
  10. #pragma mark - UIScrollView Delegate
  11. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  12. {
  13. [_pullTable tableViewDidScroll:scrollView];
  14. }
  15. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  16. {
  17. [_pullTable tableViewDidEndDragging:scrollView];
  18. }
  19. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  20. {
  21. return [_sourceArray count];
  22. }
  23. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  24. static NSString *CellIdentifier = @"cell";
  25. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  26. if (cell==nil) {
  27. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  28. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  29. }
  30. cell.textLabel.text = _sourceArray[indexPath.row];
  31. return cell;
  32. }
  33. #pragma mark - PullingRefreshTableView Delegate
  34. -(void)pullingTableViewDidStartRefreshing:(PullingRefreshTableView *)tableView
  35. {
  36. [self refreshAction];
  37. }
  38. -(void)pullingTableViewDidStartLoading:(PullingRefreshTableView *)tableView
  39. {
  40. [self loadingAction];
  41. }
  42. //处理刷新事件
  43. -(void)refreshAction
  44. {
  45. [self.sourceArray insertObject:@"下拉刷新" atIndex:0];
  46. [self performSelector:@selector(stopRefresh) withObject:nil afterDelay:1.5f];
  47. }
  48. -(void)loadingAction
  49. {
  50. [self.sourceArray addObject:@"上拉加载更多"];
  51. [self performSelector:@selector(stopRefresh) withObject:nil afterDelay:1.5f];
  52. }
  53. -(void)stopRefresh{
  54. [_pullTable tableViewDidFinishedLoading];
  55. [_pullTable reloadData];
  56. }

图片缩放和图片浏览器

图片的缩放和图片浏览器采用MWPhotoBrowser来实现,使用方法参考工程

自定义索引栏/通讯录列表;

对于常见的通讯录,部分项目上希望自定义索引兰的文字颜色、字体和背景
- 支持修改索引兰文字颜色、字体和大小
- 支持点击索引兰,处于高亮状态时的背景颜色

  1. //创建索引兰
  2. TTIIndexBar *indexBar = [[TTIIndexBar alloc] initWithFrame:CGRectMake
  3. (self.view.frame.size.width-35, 10.0, 28.0, self.view.frame.size.height-80)];
  4. indexBar.textColor = [UIColor greenColor]; //索引栏文字颜色
  5. indexBar.highlightedBackgroundColor = [UIColor redColor]; //高亮选中背景的颜色
  6. [indexBar setIndexes:[NSMutableArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G", nil]];
  7. indexBar.delegate = self;
  8. [self.view addSubview:indexBar];
  9. //处理索引兰事件
  10. #pragma mark - TTIIndexBarDelegate methods
  11. - (void)indexSelectionDidChange:(TTIIndexBar *)indexBar index:(NSInteger)index title:(NSString*)title{
  12. NSLog(@"%d %@",index,title);
  13. }

GIF加载

  1. YLImageView* imageView = [[YLImageView alloc] initWithFrame:CGRectMake(0, 160, 320, 240)];
  2. [self.view addSubview:imageView];
  3. imageView.image = [YLGIFImage imageNamed:@"joy.gif"];

自定义选择器(时间、字符串)

使用系统的选取和toolbar自定义常用的时间和字符串选择器

  1. //选择字符串
  2. TTIPickerView *pickerView = [[TTIPickerView alloc] init];
  3. pickerView.sourceArray = [NSMutableArray arrayWithArray:
  4. @[@"测试1",@"测试2",@"测试3",@"测试4",@"测试5",@"测试6"]];
  5. [pickerView show:^(NSInteger row, NSString *titleOfRow) {
  6. NSLog(@"%d %@",row,titleOfRow);
  7. }];
  8. //选择时间
  9. TTIDateView *dateView = [[TTIDateView alloc] init];
  10. [dateView show:^(NSString *dateString) {
  11. NSLog(@"%@",dateString);
  12. }];

iOS7风格的Switch

项目中通常会设计为iOS7风格的switch,但是在iOS6上的效果和iOS7上是有一定差异的,该控制支持此功能。

  1. SevenSwitch *swich = [[SevenSwitch alloc] initWithFrame: CGRectMake(260, 10, 50, 30)];
  2. [self.view addSubview: swich];

富文本控件

富文本效果

  1. //创建富文本控件
  2. self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
  3. self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  4. self.coreTextView = [[FTCoreTextView alloc] initWithFrame:CGRectInset(bounds, 20.0f, 0)];
  5. self.coreTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
  6. UIViewAutoresizingFlexibleHeight;
  7. //添加风格
  8. [self.coreTextView addStyles:[self coreTextStyle]];
  9. //设置文本
  10. self.coreTextView.text = [self textForView];
  11. self.coreTextView.delegate = self;
  12. [self.scrollView addSubview:self.coreTextView];
  13. [self.view addSubview:self.scrollView];
  14. //更多用法可参考:https://github.com/FuerteInternational/FTCoreText
  15. //可自定义设置多种样式

云标签

云标签效果图

  1. NSArray *labelARy =[NSArray arrayWithObjects:@"吃惊威龙",@"摧残人僧",@"赏金杀手",@"疯狂原始人",@"神偷奶爸",@"致命黑兰",@"冥界警局",@"狂鲨之灾",@"北海巨妖",@"海扁王2",@"变形金刚3",@"史前一亿年",@"大片",nil];
  2. //创建云标签
  3. CloudView *cv=[[CloudView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
  4. [cv reloadData:labelARy];
  5. [self.view addSubview:cv];
  6. [cv setBackgroundColor: [UIColor blackColor]];

广告页Banners循环滚动效果

采用类似UItableview的委托形式,创建支持循环滚动的Banners效果控件

  1. self.cycleScrollView = [[TTICycleScrollView alloc] initWithFrame:CGRectMake(0, 30, 320, 100)];
  2. self.cycleScrollView.delegate = self;
  3. self.cycleScrollView.datasource = self;
  4. [self.view addSubview:self.cycleScrollView];
  5. for (int i = 0; i < 10; i++) {
  6. NSString *num = [NSString stringWithFormat:@"%d_index",i + 1];
  7. [self.dataSource addObject:num];
  8. }
  9. [self.cycleScrollView reloadData];
  10. //设置代理和数据源
  11. #pragma mark - TTICycleScrollViewDelegate methods
  12. - (void)didClickPage:(TTICycleScrollView *)csView atIndex:(NSInteger)index{
  13. //点击事件
  14. }
  15. #pragma mark - TTICycleScrollViewDatasource methods
  16. - (NSInteger)numberOfPages{
  17. return self.dataSource.count;
  18. }
  19. - (UIView *)pageAtIndex:(NSInteger)index{
  20. //这里的视图可以根据实际情况自定义
  21. UILabel *tip = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
  22. if (index%3 == 0) {
  23. tip.backgroundColor = [UIColor redColor];
  24. }else if (index%3 == 1){
  25. tip.backgroundColor = [UIColor grayColor];
  26. }else{
  27. tip.backgroundColor = [UIColor greenColor];
  28. }
  29. tip.text = [self.dataSource objectAtIndex:index];
  30. tip.textColor = [UIColor blackColor];
  31. tip.textAlignment = NSTextAlignmentCenter;
  32. return tip;
  33. }

饼图、折线图、条形图

使用开源PNChart控件(https://github.com/kevinzhow/PNChart)和自定义的TTIGoalBar实现三种风格图标

自由截图视图

截图当前屏幕的图片

拼音视图

中文转换为拼音

自定义的控制器、导航控制器和标签栏控制器

继承系统的UIViewController、UINavagationContoller和UITabbarController,支持更多自定义操作,满足实际项目需求

瀑布流和分页加载

使用PSCollectionView和顶部、尾部加载控件,实现瀑布流和分页加载效果

自定义评分控件

支持评分和仅显示星级数功能

自定义滑动cell

自定义TextView和TextFIled

自定义PageControl


功能类

拍照/拍视频/录音

提供常见的拍照、拍适配和录音频的操作

  1. //选择图片
  2. WEAKSELF
  3. [[TTIImagePickerManager shareInstance] imagePickerWithType:TTIImagePickerManagerBoth enableEditing:YES withDelegate:self comleteBlock:^(UIImage *resultImage, UIImage *orignImage) {
  4. weakSelf.selectImage.image = resultImage;
  5. } failedBlock:^(NSError *error) {
  6. }];
  7. //选择视频
  8. [[TTIVideoPickerManager shareInstance] videoPickerWithType:TTIVideoPickerManagerBoth withDelegate:self isConvertMP4:NO comleteBlock:^(NSString *resultPath, NSString *orignPath) {
  9. NSLog(@"视频地址:%@",resultPath);
  10. } failedBlock:^(NSError *error) {
  11. }];
  12. //选择音频
  13. [[TTIAudioPickerManager shareInstance] audioPickerWithType:TTIAudioPickerManagerBoth withDelegate:self isConvertMP3:YES comleteBlock:^(NSString *resultPath, NSString *orignPath) {
  14. NSLog(@"音频地址:%@",resultPath);
  15. } failedBloc:^(NSError *error) {
  16. }];

打电话、发短信、发邮件

常见工具操作

二维码扫描

使用ZBar进行二维码扫描功能

ZIP文件的解压与压缩

对于数据包的形式,通常需要进行文件的压缩和解压

应用内语言切换

强制在程序内部进行语言切换


工具类

字符串处理

图片工具类

日志工具类

日期工具类

验证工具类

常用数据格式判断
- 手机号
- 邮箱
- 身份证
- 电话
- 纯数字
- 用户名和昵称
- ...

字体工具类

对话框工具类

加密处理

视图工具类

动画工具类


动画类

磨盘效果控件

3D画廊

360、720度全景

导航控制器切换效果

抽屉效果


数据存储

使用UserDefaults存储用户信息

使用Plist存储信息

SQList数据操作存储,采用FMDB操作

CoreData数据存储


网络操作

数据对象操作(自动映射)

使用开源控件JSONModel(https://github.com/icanzilb/JSONModel)完成,支持如下功能:

Http网络接口操作

基于开源库AFNetworking(https://github.com/AFNetworking/AFNetworking)封装的请求类:
- TTIHttpClient处理所有接口请求和操作
- TTIRequest处理网络请求信息
- TTIResponse处理网络返回数据信息

TCP Socket通信操作

基于开源库CocoaAsyncSocket(https://github.com/robbiehanson/CocoaAsyncSocket)封装的请求类
- TTISocketClient处理tcp连接、断开、重连、信息发送和粘包等处理
- TTISocketRequest处理发送出去的帧信息
- TTISocketResponse处理接受到的帧信息

网络状况判断


第三方平台

分享

支付

地图

统计

推送

推送中需注意的事项:


常用开源库

AFNetworking网络

SVProgressHUD和SVPullToRefresh

YLGIFImage

SDWebimage加载图片

OpenUDID

JSONModel

iCarousel常用转动效果

FTCoreText富文本排版

VVDoucumenter代码注释工具


TODO

  1. iOS代码库使用.a文件生成
  2. 完善iOS代码库内容
  3. 整理和清晰代码库提交流程和审核流程
  4. 使用iOS代码库,创建项目模板工程
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注