ios 团购分类页面(9宫格)
=-= 命名有些错误,但功能实现,以后注意下命名规范
WJViewGroup.h
#import <UIKit/UIKit.h>
@interface WJViewGroup : UIView {
NSInteger _width;
NSInteger _height;
}
@property (nonatomic,assign)NSInteger widthNum; //横排多少个
@property (nonatomic,assign)NSInteger heightNum; //竖排多少个
@property (copy, nonatomic) void(^itemBlock)(NSInteger index);//按钮点击回调
@property (nonatomic,assign)BOOL isLine;
@property (nonatomic,strong)NSMutableArray *array;
/**
* 添加item
*
* @param widthItem 高数量
* @param heightItem 宽数量
* @param num item数量
*/
- (void)addItem:(NSInteger)widthItem widthItem:(NSInteger)heightItem num:(NSArray *)num;
/**
* 改变item的文字
*
* @param array 文字数组
*/
- (void)item:(NSArray *)array;
@end
WJViewGroup.m
#import "WJViewGroup.h"
@implementation WJViewGroup
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_width = frame.size.width;
self.backgroundColor = [UIColor whiteColor];
_height = frame.size.height;
self.layer.borderWidth = ;
self.clipsToBounds = YES;
self.layer.cornerRadius = ;
_widthNum = ;
_heightNum = ;
_array = [[NSMutableArray alloc]init];
}
return self;
}
#pragma mark - 添加item 3行---------
- (void)addItem:(NSInteger)widthItem widthItem:(NSInteger)heightItem num:(NSArray *)num{
NSInteger index = ;
NSInteger indeNume = ;
for (NSInteger i = ; i < widthItem; i ++) {
NSInteger index_Y = ;
for (NSInteger j = ; j < heightItem; j++) {
if (indeNume < num.count) {
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(_width/_widthNum*index_Y, _height/_heightNum * index, _width/_widthNum, _height/_heightNum)];
[button setTitle:num[indeNume] forState:UIControlStateNormal];
button.tag = indeNume;
button.titleLabel.font = [UIFont systemFontOfSize:];
[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
[_array addObject:button];
if (_isLine && index_Y < ) {
UIView *lineVertical = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(button.frame), CGRectGetMinY(button.frame) + _height/_heightNum *0.2, 0.5, _height/_heightNum *0.6)];
lineVertical.backgroundColor = [UIColor lightGrayColor];
[self addSubview:lineVertical];
}
}
indeNume ++;
index_Y++;
}
index++;
}
if (_isLine) {
[self addCrossLine:];
}
}
- (void)item:(NSArray *)array {
NSInteger index = ;
for (UIButton *button in _array) {
if (index < array.count) {
[button setTitle:array[index] forState:UIControlStateNormal];
}
index++;
}
}
#pragma mark - 添加横竖线
- (void)addCrossLine:(NSInteger)index {
if (index == ) {
for (int i = ; i < ; i ++) {
if (i > ) {
UIView *crossLine = [[UIView alloc]initWithFrame:CGRectMake(_width *0.05, _height/_heightNum*i, _width *0.9, 0.5)];
crossLine.backgroundColor = [UIColor lightGrayColor];
[self addSubview:crossLine];
}
}
}else {
for (int i = ; i < ; i ++) {
if (i > ) {
UIView *crossLine = [[UIView alloc]initWithFrame:CGRectMake(, _height/_heightNum*i, _width, 0.5)];
crossLine.backgroundColor = [UIColor lightGrayColor];
[self addSubview:crossLine];
}
}
}
}
- (void)addVerticalLine {
for (int i = ; i < ; i ++) {
if (i < ) {
UIView *verticalLine = [[UIView alloc]initWithFrame:CGRectMake(_width/_widthNum * (i+),, _width, 0.5)];
verticalLine.backgroundColor = [UIColor grayColor];
[self addSubview:verticalLine];
}
}
}
#pragma mark - 事件监听
- (void)buttonPressed:(UIButton *)sender {
if (sender.titleLabel.text.length > ) {
if (_itemBlock) {
_itemBlock(sender.tag);
}
}
}
@end
使用:
1.直接使用
WJViewGroup *group = [[WJViewGroup alloc]initWithFrame:CGRectMake(ScreenWidth*0.05, , ScreenWidth*0.9, )];
group.isLine = YES; group.layer.borderColor = [UIColor colorWithHexString:@"d3d1d1"].CGColor;
[group addItem: widthItem: num:@[@"美食",@"电影",@"KTV",@"龙虾",@"甜品",@"海鲜",@"火锅",@"自助餐",@"蔬菜"]];
[group setItemBlock:^(NSInteger index) {
NSLog(@"%ld",index); }];
[self.view addSubview:group];
效果图:
2.cell中使用
自定义初始化cell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier cellHeight:(NSInteger)cellHeight;
_group = [[WJViewGroup alloc]initWithFrame:CGRectMake(ScreenWidth*0.05, CGRectGetHeight(viewBG.frame) +, ScreenWidth*0.9, cellHeight)];
_group.isLine = YES;
if (cellHeight == ) {
_group.heightNum = ;
}
_group.layer.borderColor = [UIColor colorWithHexString:@"d3d1d1"].CGColor;
[_group addItem: widthItem: num:@[@"",@"",@"",@"",@"",@"",@"",@"",@""]];
[self.contentView addSubview:_group];
懒加载:
- (NSArray *)arrayContext {
if (!_arrayContext) {
_arrayContext = [[NSArray alloc]initWithObjects:
@[@"火锅",@"蛋糕甜点",@"西餐",@"自助餐",@"小吃快餐",@"香锅烤鱼",@"聚餐宴请",@"烧烤烤肉",@"日韩料理"],
@[@"经济型酒店",@"豪华酒店",@"主题酒店",@"公寓型酒店",@"客栈",@"青年旅社"],
@[@"美发",@"美甲",@"美容美体",@"瑜伽/舞蹈"],
@[@"温泉",@"海洋馆",@"展览馆",@"动植物园",@"主题公园",@"水上乐园"],
@[@"演出赛事",@"桌游/电玩",@"运动健身",@"足疗按摩",@"洗浴/汗蒸",@"4D/5D电影",],
nil];
}
return _arrayContext;
}
代理方法中:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
[cell.group item:self.arrayContext[indexPath.row]];
[cell.group setItemBlock:^(NSInteger index) {
NSLog(@"%ld",index); }];
效果图:
ios 团购分类页面(9宫格)的更多相关文章
- ios 团购信息客户端demo(一)
团购信息客户端,主要整合了ASIHTTPREQUEST,KISSXML,AQGridView,MBProgressHUD这几个主要流行的IOS开发库,我们先来看一下效果图 首先我们新建一个IOS工程, ...
- ios 团购信息客户端demo(三)
接上二篇的内容,今天我们就来介绍一下如何将解析出来的数据放入AQGridView中显示出来,因为我们的工程中已经将AQGridView导入了,所以我们在KKFirstViewController中直接 ...
- ios 团购信息客户端demo(二)
接上一篇,这篇我们对我们的客户端加入KissXML,MBProgressHUD,AQridView这几个库,首先我们先加入KissXML,这是XML解析库,支持Xpath,可以方便添加更改任何节点.先 ...
- iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局
iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局 一.项目文件结构和plist文件 二.实现效果 三.代码示例 1.没有使用配套的类,而是直接使用xib文 ...
- iOS开发:一个高仿美团的团购ipad客户端的设计和实现(功能:根据拼音进行检索并展示数据,离线缓存团购数据,浏览记录与收藏记录的批量删除等)
大致花了一个月时间,利用各种空闲时间,将这个客户端实现了,在这里主要是想记录下,设计的大体思路以及实现过程中遇到的坑...... 这个项目的github地址:https://github.com/wz ...
- iOS开发——UI进阶篇(二)自定义等高cell,xib自定义等高的cell,Autolayout布局子控件,团购案例
一.纯代码自定义等高cell 首先创建一个继承UITableViewCell的类@interface XMGTgCell : UITableViewCell在该类中依次做一下操作1.添加子控件 - ( ...
- IOS第八天(2:UITableViewController团购,点击底部,xib加载更多, 代理模式)
******* HMViewController.h #import "HMViewController.h" #import "HMTg.h" #import ...
- [iOS基础控件 - 6.6.1] 展示团购数据代码
1.主控制器: // // ViewController.m // GroupPurchase // // Created by hellovoidworld on 14/12/3. // Cop ...
- [iOS基础控件 - 6.6] 展示团购数据 自定义TableViewCell
A.需求 1.头部广告 2.自定义cell:含有图片.名称.购买数量.价格 3.使用xib设计自定义cell,自定义cell继承自UITableViewCell 4.尾部“加载更多按钮”,以及其被点击 ...
随机推荐
- Google Chrome浏览器各版本直接下载地址
Google Chrome浏览器各版本直接下载地址 2012.04.12珍藏软件 10161 Views 0 Comments 现在所用的主浏览器Google Chrome,在其官方主页上默认只 ...
- linux kernel 0.11 head
head的作用 注意:bootsect和setup汇编采用intel的汇编风格,而在head中,此时已经进入32位保护模式,汇编的采用的AT&T的汇编语言,编译器当然也就变成对应的编译和连接器 ...
- SQL注入式攻击
百度百科:http://baike.baidu.com/link?url=GQbJ2amTzTahZA7XJSBDLYYkN3waQ9JCoJ0l--tCWlvKQibe0YaH4hpmgEnLyn0 ...
- 【6.24-AppCan移动开发大会倒计时】科大讯飞来了!
6.24 AppCan移动开发者大会进入倒计时,报名通道即将关闭! 50多家移动圈服务商将出席此次大会,讯飞开放平台也将作为参展商,为参会者带去前沿的语音技术.参会者可现场体验最新连续语音识别技术,识 ...
- android开发图片分辨率问题解决方案
dpi是什么呢? dpi是“dot per inch”的缩写,每英寸像素数. 四种密度分类: ldpi (low), mdpi (medium), hdpi (high), and xhdpi (ex ...
- [原创]flexslider 中文文档 使用教程 参数手册
要改前人用的flexslider功能,但苦于找不到详细的文档教程,折磨了好久……(所以我才说不爱乱用插件) 为了福利下之后也苦于这个问题的人,我整理总结了下我找到的一些东西.可能没那么完善正确,欢迎在 ...
- 用Sqlplus手动创建Oracle11g数据库
用Sqlplus手动创建Oracle数据库 刚开始学习Oracle数据库,菜鸟一个,使用sqlplus创建数据库遇到了很多问题,通过不断地百度,终于创建成功了.所以顺便把整个过程中犯的一些最低级的错误 ...
- Unity3d之Animation(动画系统)
1,动画系统配置,2,代码控制动画 原文地址: http://blog.csdn.net/dingkun520wy/article/details/51247487 1,动画系统配置 创建游戏对象并添 ...
- DataTemplate和ControlTemplate联系与区别
---恢复内容开始--- 正如标题中的两个拼接的单词所说,DataTemplate就是数据显示的模板,而ControlTemplate是控件自身的模板.(个人理解,错误请指出,谢谢) 我们看这二者在两 ...
- Implementation Documentation[转]
原文地址:http://prasanna-adf.blogspot.tw/2009/04/implementation-documentation.html Following are the lis ...