XTImageGridView 0.5.0

XTImageGridView 0.5.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
版本最新版本2017年10月

Ronnie Chen维护。




  • 作者:
  • Ronnie Chen

XTImageGridView是一个用于在iOS中构建网格视图的非常简单的库。

##哪些场景可以使用这个库?

Scene1
Scene2

##配置
#####1.将XTImageGirdView SDWebImage添加到您的项目中。
#####2.添加代码#import "XTImageGirdView.h"
#####3.初始代码

self.gridView = [[XTImageGridView alloc] init];
_gridView.frame = CGRectMake(0, 0, XTScreenSize.width, self.view.bounds.size.height);
_gridView.edgeInsets = UIEdgeInsetsMake(45, (XTScreenSize.width-270)*0.5, 5, (XTScreenSize.width-270)*0.5);
_gridView.gridViewDelegate = self;
[self.view addSubview:_gridView];
[self.gridView reloadData];

#####4.刷新网格视图

_gridView.maxNumInRow = 10;
_gridView.numOfImageViews = 10;
[self.gridView reloadData];

#####5.配置单个视图
######XTImageGirdView有两种风格。
一种是XTImageGridViewStyleDefault,在这个风格中,网格视图默认有一个
添加按钮在最后。您可以隐藏或显示它。默认的单个视图有一个图像视图,还有一个删除按钮。
如果您想删除视图,您应该在视图中长按,然后删除按钮将显示并伴有
摇晃动画。您还可以配置它直接显示。

Default

###长按后。

Animation1
Animation2

###另一种风格是XTImageGridViewStyleCustom,您可以通过自己自定义单个视图。

Default1
Default2
#####以下为XTImageGridViewStyleDefault的代理方法可以配置视图

-(NSDictionary *)imageSourcesAtIndex:(int)index InGridView:(XTImageGridView *)gridView
{
	return @{@"name":[_attachArray objectAtIndex:index],@"isURL":@NO};
}

#####以下为XTImageGridViewStyleCustom的代理方法可以配置视图

-(void)customViewAtIndex:(int)index CurrentView:(UIView *)curView InGridView:(XTImageGridView *)gridView
{
	//	curView.layer.borderColor = [UIColor redColor].CGColor;
	//	curView.layer.borderWidth = 2.0;
	
	CGFloat headViewWidth = 44.0;
	CGFloat headViewHeight = 44.0;
	CGFloat headViewX = (curView.bounds.size.width-headViewWidth)*0.5;
	CGFloat headViewY = (curView.bounds.size.height-headViewHeight)*0.5-10;
	UIImageView *headView = [[UIImageView alloc] initWithFrame:CGRectMake(headViewX, headViewY, 44, 44)];
	//	headView.backgroundColor = [UIColor redColor];
	headView.layer.cornerRadius = headViewWidth*0.5;
	headView.layer.borderWidth = 5.0;
	headView.layer.borderColor = [UIColor whiteColor].CGColor;
	headView.clipsToBounds = YES;
	[curView addSubview:headView];
	
	UIView *headViewLayer = [[UIView alloc] initWithFrame:CGRectMake(headViewX, headViewY, 44, 44)];
	headViewLayer.backgroundColor = [UIColor clearColor];
	headViewLayer.layer.borderColor = [UIColor colorWithRed:82/255.0 green:145/255.0 blue:24/255.0 alpha:1.0].CGColor;
	headViewLayer.layer.cornerRadius = headViewWidth*0.5;
	headViewLayer.layer.borderWidth = 1.0;
	headViewLayer.clipsToBounds = YES;
	[curView addSubview:headViewLayer];
	
	UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, headViewY-20, curView.bounds.size.width, 20)];
	nameLabel.text = @"Lily";
	nameLabel.font = [UIFont systemFontOfSize:13.0];
	nameLabel.textColor = [UIColor colorWithRed:31/255.0 green:31/255.0 blue:31/255.0 alpha:1.0];
	nameLabel.textAlignment = NSTextAlignmentCenter;
	[curView addSubview:nameLabel];
	
	UILabel *statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(headView.frame)+2, curView.bounds.size.width, 20)];
	statusLabel.text = @"Agree";
	statusLabel.font = [UIFont systemFontOfSize:13.0];
	statusLabel.textColor = [UIColor colorWithRed:31/255.0 green:31/255.0 blue:31/255.0 alpha:1.0];
	statusLabel.textAlignment = NSTextAlignmentCenter;
	[curView addSubview:statusLabel];
	
	UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(statusLabel.frame), curView.bounds.size.width, 20)];
	timeLabel.text = @"2016.07.08";
	timeLabel.font = [UIFont systemFontOfSize:13.0];
	timeLabel.textColor = [UIColor colorWithRed:111/255.0 green:111/255.0 blue:111/255.0 alpha:1.0];
	timeLabel.textAlignment = NSTextAlignmentCenter;
	[curView addSubview:timeLabel];
	
	if (index != gridView.numOfImageViews-1) {
		
		UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(curView.bounds.size.width-12.5, CGRectGetMidY(headView.frame)-1, 12.5, 2.0)];
		lineView1.backgroundColor = [UIColor colorWithRed:212/255.0 green:212/255.0 blue:212/255.0 alpha:1.0];
		[curView addSubview:lineView1];
	}
	
	if (index != 0) {
		
		UIView *lineView2 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMidY(headView.frame)-1, 12.5, 2.0)];
		lineView2.backgroundColor = [UIColor colorWithRed:212/255.0 green:212/255.0 blue:212/255.0 alpha:1.0];
		[curView addSubview:lineView2];
	}
	
	
}

#####6.代理方法

/**
 *  clicked add button
 */
-(void)addBtnClickedInGridView:(XTImageGridView *)gridView;
/**
 *  clicked delete button
 */
-(void)deleteBtnClickedAtIndex:(int)index InGridView:(XTImageGridView *)gridView;
/**
 *  clicked grid view
 */
-(void)viewClickedAtindex:(int)index InGridView:(XTImageGridView *)gridView;

#####7.属性

/**
 *  should show or hide add button
 */
@property (nonatomic,assign) BOOL showAddBtn;
/**
 *  should show or hide delete button
 */
@property (nonatomic,assign) BOOL showDeleteBtn;
/**
 *  should use shake animation when show delete button.
 */
@property (nonatomic,assign) BOOL showShakeAnimationWhenShowDeleteBtn;
/**
 *  grid view style
 */
@property (nonatomic,assign) XTImageGridViewStyle gridViewStyle;
/**
 *  grid numbers
 */
@property (nonatomic,assign) int numOfImageViews;
/**
 *  max numbers in one row
 */
@property (nonatomic,assign) int maxNumInRow;
/**
 *  two view's gap in one column
 */
@property (nonatomic,assign) CGFloat gapOfTwoViewInCol;
/**
 *  two view's gap in one row
 */
@property (nonatomic,assign) CGFloat gapOfTwoViewInRow;
/**
 *  grid view's size
 */
@property (nonatomic,assign) CGSize singleViewSize;
/**
 *  left,top,right,bottom margin
 */
@property (nonatomic,assign) UIEdgeInsets edgeInsets;