九宫格
来源:互联网 发布:js屏蔽手机运营商广告 编辑:程序博客网 时间:2024/04/29 20:08
#import
#import
@interface NineGridEntity : NSObject
@property (nonatomic, strong) NSString* id;
@property (nonatomic, strong) NSString* name;
@property (nonatomic, strong) NSString* ImageName;
@property (nonatomic, strong) UIImage* icon;
@property (nonatomic, strong) NSString * unreadcount;
@property (nonatomic) int sortno;
@property (nonatomic, strong)UIImageView *iconIV;
@end
#import "NineGridEntity.h"
@implementation NineGridEntity
//@synthesizeid,name,icon,sortno,unreadcount,ImageName,iconIV;
@end
#import
@protocol NineGridTableDelegate
-(void)onClickNineGridTableButton:(NSString*)objid;
@end
@interface NineGridTable : UITableView
-(void)loadGridData:(NSMutableArray*)dataArray;
@property (nonatomic, assign) id nineGridTableDelegate;
@property (nonatomic, assign) int countinrow;
//设置表格单元格样式
+(void)setTableCellStyle:(UITableViewCell*)cell;
@end
#import "NineGridTable.h"
#import "NineGridEntity.h"
#import "UIImage+imageAlpha.h"
@interface NineGridTable(){
NSMutableArray* dataArrays;
}
@end
@implementation NineGridTable
@synthesize nineGridTableDelegate;
@synthesize countinrow;
- (id)initWithFrame:(CGRect)frame
{
self =[super initWithFrame:frame];
if (self){
// Initialization code
}
self.backgroundColor = [UIColor whiteColor];
self.allowsSelection = FALSE;
self.dataSource = self;
self.delegate = self;
[selfsetSeparatorColor:[UIColor clearColor]];
self.countinrow = 3;
returnself;
}
-(void)loadGridData:(NSMutableArray*)dataArray{
dataArrays =[[NSMutableArray alloc] initWithArray:dataArray];
[selfreloadData];
}
- (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section{
returndataArrays.count % self.countinrow >0 ? dataArrays.count /self.countinrow + 1 : dataArrays.count / self.countinrow;
}
- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString*ListViewCellId = @"NineGridCellId";
CGFloatbuttonheight = tableView.frame.size.width / (self.countinrow +4.0f);
CGFloatbuttonwidth = buttonheight;
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:ListViewCellId];
if (cell ==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:ListViewCellId];
CGFloat sidewidth = (tableView.frame.size.width -buttonheight*self.countinrow) / (self.countinrow + 1.0f);
CGFloat sideheight = (tableView.frame.size.width / self.countinrow-buttonheight) / 2.0f;
for(int i=0; i
UIButton* button1 = [UIButtonbuttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(sidewidth * (i+1) + buttonwidth*i,sideheight, buttonwidth, buttonheight);
button1.backgroundColor = [UIColor whiteColor];
button1.tag = 1001 + i;
[cell.contentView addSubview:button1];
[button1 addTarget:self action:@selector(buttonClickImage:)forControlEvents:UIControlEventTouchUpInside];
}
for(int i=0; i
UIButton* button1 = (UIButton*)[cell.contentViewviewWithTag:(1001+i)];
#import
@interface NineGridEntity : NSObject
@property (nonatomic, strong) NSString* id;
@property (nonatomic, strong) NSString* name;
@property (nonatomic, strong) NSString* ImageName;
@property (nonatomic, strong) UIImage* icon;
@property (nonatomic, strong) NSString * unreadcount;
@property (nonatomic) int sortno;
@property (nonatomic, strong)UIImageView *iconIV;
@end
#import "NineGridEntity.h"
@implementation NineGridEntity
//@synthesizeid,name,icon,sortno,unreadcount,ImageName,iconIV;
@end
#import
@protocol NineGridTableDelegate
-(void)onClickNineGridTableButt
@end
@interface NineGridTable : UITableView
-(void)loadGridData:(NSMutableArray*)dataArray;
@property (nonatomic, assign)
@property (nonatomic, assign) int countinrow;
//设置表格单元格样式
+(void)setTableCellStyle:(UITableViewCell*)cell;
@end
#import "NineGridTable.h"
#import "NineGridEntity.h"
#import "UIImage+imageAlpha.h"
@interface NineGridTable(){
}
@end
@implementation NineGridTable
@synthesize nineGridTableDelegate;
@synthesize countinrow;
- (id)initWithFrame:(CGRect)frame
{
}
-(void)loadGridData:(NSMutableArray*)dataArray{
}
- (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section{
}
- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath{