@FoxBabe
2014-09-25T09:06:19.000000Z
字数 9596
阅读 4707
代码库 iOS 控件

TTILibrary
- Category (常用扩展)
- Helper (常用工具类)
- Macro (公共宏和第三方参数宏)
- NetWork(网络相关操作)
- UI(常用控件)
iOSCodeProject (项目名称,可根据实际进行修改)
- Resource (项目中常用资源)
- Depend (常用依赖库)
- Models (对象数据)
- Views (项目中共用控件)
- Controlers (项目中的控制器层)
使用PullingRefreshTableView实现上下拉动和分页效果,基本使用:
//创建列表self.pullTable = [[PullingRefreshTableView alloc] init];self.pullTable.frame = self.view.bounds;self.pullTable.delegate=self;self.pullTable.dataSource = self;self.pullTable.pullingDelegate = self;self.pullTable.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleBottomMargin;[self.view addSubview:self.pullTable];//设置委托#pragma mark - UIScrollView Delegate-(void)scrollViewDidScroll:(UIScrollView *)scrollView{[_pullTable tableViewDidScroll:scrollView];}- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{[_pullTable tableViewDidEndDragging:scrollView];}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return [_sourceArray count];}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{static NSString *CellIdentifier = @"cell";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];if (cell==nil) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];cell.selectionStyle = UITableViewCellSelectionStyleNone;}cell.textLabel.text = _sourceArray[indexPath.row];return cell;}#pragma mark - PullingRefreshTableView Delegate-(void)pullingTableViewDidStartRefreshing:(PullingRefreshTableView *)tableView{[self refreshAction];}-(void)pullingTableViewDidStartLoading:(PullingRefreshTableView *)tableView{[self loadingAction];}//处理刷新事件-(void)refreshAction{[self.sourceArray insertObject:@"下拉刷新" atIndex:0];[self performSelector:@selector(stopRefresh) withObject:nil afterDelay:1.5f];}-(void)loadingAction{[self.sourceArray addObject:@"上拉加载更多"];[self performSelector:@selector(stopRefresh) withObject:nil afterDelay:1.5f];}-(void)stopRefresh{[_pullTable tableViewDidFinishedLoading];[_pullTable reloadData];}
图片的缩放和图片浏览器采用MWPhotoBrowser来实现,使用方法参考工程
对于常见的通讯录,部分项目上希望自定义索引兰的文字颜色、字体和背景
- 支持修改索引兰文字颜色、字体和大小
- 支持点击索引兰,处于高亮状态时的背景颜色
//创建索引兰TTIIndexBar *indexBar = [[TTIIndexBar alloc] initWithFrame:CGRectMake(self.view.frame.size.width-35, 10.0, 28.0, self.view.frame.size.height-80)];indexBar.textColor = [UIColor greenColor]; //索引栏文字颜色indexBar.highlightedBackgroundColor = [UIColor redColor]; //高亮选中背景的颜色[indexBar setIndexes:[NSMutableArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G", nil]];indexBar.delegate = self;[self.view addSubview:indexBar];//处理索引兰事件#pragma mark - TTIIndexBarDelegate methods- (void)indexSelectionDidChange:(TTIIndexBar *)indexBar index:(NSInteger)index title:(NSString*)title{NSLog(@"%d %@",index,title);}
YLImageView* imageView = [[YLImageView alloc] initWithFrame:CGRectMake(0, 160, 320, 240)];[self.view addSubview:imageView];imageView.image = [YLGIFImage imageNamed:@"joy.gif"];
使用系统的选取和toolbar自定义常用的时间和字符串选择器
//选择字符串TTIPickerView *pickerView = [[TTIPickerView alloc] init];pickerView.sourceArray = [NSMutableArray arrayWithArray:@[@"测试1",@"测试2",@"测试3",@"测试4",@"测试5",@"测试6"]];[pickerView show:^(NSInteger row, NSString *titleOfRow) {NSLog(@"%d %@",row,titleOfRow);}];//选择时间TTIDateView *dateView = [[TTIDateView alloc] init];[dateView show:^(NSString *dateString) {NSLog(@"%@",dateString);}];
项目中通常会设计为iOS7风格的switch,但是在iOS6上的效果和iOS7上是有一定差异的,该控制支持此功能。
SevenSwitch *swich = [[SevenSwitch alloc] initWithFrame: CGRectMake(260, 10, 50, 30)];[self.view addSubview: swich];

//创建富文本控件self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];self.scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;self.coreTextView = [[FTCoreTextView alloc] initWithFrame:CGRectInset(bounds, 20.0f, 0)];self.coreTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;//添加风格[self.coreTextView addStyles:[self coreTextStyle]];//设置文本self.coreTextView.text = [self textForView];self.coreTextView.delegate = self;[self.scrollView addSubview:self.coreTextView];[self.view addSubview:self.scrollView];//更多用法可参考:https://github.com/FuerteInternational/FTCoreText//可自定义设置多种样式
云标签效果图
NSArray *labelARy =[NSArray arrayWithObjects:@"吃惊威龙",@"摧残人僧",@"赏金杀手",@"疯狂原始人",@"神偷奶爸",@"致命黑兰",@"冥界警局",@"狂鲨之灾",@"北海巨妖",@"海扁王2",@"变形金刚3",@"史前一亿年",@"大片",nil];//创建云标签CloudView *cv=[[CloudView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];[cv reloadData:labelARy];[self.view addSubview:cv];[cv setBackgroundColor: [UIColor blackColor]];
采用类似UItableview的委托形式,创建支持循环滚动的Banners效果控件
self.cycleScrollView = [[TTICycleScrollView alloc] initWithFrame:CGRectMake(0, 30, 320, 100)];self.cycleScrollView.delegate = self;self.cycleScrollView.datasource = self;[self.view addSubview:self.cycleScrollView];for (int i = 0; i < 10; i++) {NSString *num = [NSString stringWithFormat:@"%d_index",i + 1];[self.dataSource addObject:num];}[self.cycleScrollView reloadData];//设置代理和数据源#pragma mark - TTICycleScrollViewDelegate methods- (void)didClickPage:(TTICycleScrollView *)csView atIndex:(NSInteger)index{//点击事件}#pragma mark - TTICycleScrollViewDatasource methods- (NSInteger)numberOfPages{return self.dataSource.count;}- (UIView *)pageAtIndex:(NSInteger)index{//这里的视图可以根据实际情况自定义UILabel *tip = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];if (index%3 == 0) {tip.backgroundColor = [UIColor redColor];}else if (index%3 == 1){tip.backgroundColor = [UIColor grayColor];}else{tip.backgroundColor = [UIColor greenColor];}tip.text = [self.dataSource objectAtIndex:index];tip.textColor = [UIColor blackColor];tip.textAlignment = NSTextAlignmentCenter;return tip;}
使用开源PNChart控件(https://github.com/kevinzhow/PNChart)和自定义的TTIGoalBar实现三种风格图标
截图当前屏幕的图片
中文转换为拼音
继承系统的UIViewController、UINavagationContoller和UITabbarController,支持更多自定义操作,满足实际项目需求
使用PSCollectionView和顶部、尾部加载控件,实现瀑布流和分页加载效果
支持评分和仅显示星级数功能
提供常见的拍照、拍适配和录音频的操作
//选择图片WEAKSELF[[TTIImagePickerManager shareInstance] imagePickerWithType:TTIImagePickerManagerBoth enableEditing:YES withDelegate:self comleteBlock:^(UIImage *resultImage, UIImage *orignImage) {weakSelf.selectImage.image = resultImage;} failedBlock:^(NSError *error) {}];//选择视频[[TTIVideoPickerManager shareInstance] videoPickerWithType:TTIVideoPickerManagerBoth withDelegate:self isConvertMP4:NO comleteBlock:^(NSString *resultPath, NSString *orignPath) {NSLog(@"视频地址:%@",resultPath);} failedBlock:^(NSError *error) {}];//选择音频[[TTIAudioPickerManager shareInstance] audioPickerWithType:TTIAudioPickerManagerBoth withDelegate:self isConvertMP3:YES comleteBlock:^(NSString *resultPath, NSString *orignPath) {NSLog(@"音频地址:%@",resultPath);} failedBloc:^(NSError *error) {}];
常见工具操作
使用ZBar进行二维码扫描功能
对于数据包的形式,通常需要进行文件的压缩和解压
强制在程序内部进行语言切换
常用数据格式判断
- 手机号
- 邮箱
- 身份证
- 电话
- 纯数字
- 用户名和昵称
- ...
使用开源控件JSONModel(https://github.com/icanzilb/JSONModel)完成,支持如下功能:
基于开源库AFNetworking(https://github.com/AFNetworking/AFNetworking)封装的请求类:
- TTIHttpClient处理所有接口请求和操作
- TTIRequest处理网络请求信息
- TTIResponse处理网络返回数据信息
基于开源库CocoaAsyncSocket(https://github.com/robbiehanson/CocoaAsyncSocket)封装的请求类
- TTISocketClient处理tcp连接、断开、重连、信息发送和粘包等处理
- TTISocketRequest处理发送出去的帧信息
- TTISocketResponse处理接受到的帧信息
推送中需注意的事项: