Initial commit

This commit is contained in:
ifish
2017-08-15 16:59:01 +08:00
commit bdc83e07ef
5766 changed files with 423223 additions and 0 deletions
@@ -0,0 +1,22 @@
//
// UMComActionDeleteView.h
// UMCommunity
//
// Created by luyiyuan on 14/9/16.
// Copyright (c) 2014年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, UMComActionDeleteViewType)
{
UMComActionDeleteViewType_Circle,//圆形
UMComActionDeleteViewType_Rectangle,//矩形
};
@interface UMComActionDeleteView : UIView
@property(nonatomic,assign)UMComActionDeleteViewType deleteViewType;
@end
@@ -0,0 +1,94 @@
//
// UMComActionDeleteView.m
// UMCommunity
//
// Created by luyiyuan on 14/9/16.
// Copyright (c) 2014年 Umeng. All rights reserved.
//
#import "UMComActionDeleteView.h"
@implementation UMComActionDeleteView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
// self.userInteractionEnabled = YES;
}
return self;
}
- (CGSize)sizeThatFits:(CGSize)size
{
return CGSizeMake(24.0, 24.0);
}
-(void)doDrawCircle:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
// Border
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextFillEllipseInRect(context, self.bounds);
// Body
CGContextSetRGBFillColor(context, 1.0, 0, 0, 1.0);
CGContextFillEllipseInRect(context, CGRectInset(self.bounds, 1.0, 1.0));
// Checkmark
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetLineWidth(context, 1.2);
CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGContextMoveToPoint(context, center.x- self.bounds.size.width/4,center.y);
CGContextAddLineToPoint(context, center.x + self.bounds.size.width/4,center.y);
CGContextStrokePath(context);
}
-(void) doDrawRectangle:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
//设置背景填充
CGContextSetRGBFillColor(context, 0.3, 0.3, 0.3, 0.8);
CGContextFillRect(context, rect);
//画线
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 0.9);
CGContextSetLineWidth(context, 0.5);
//设置对称的坐标点
int offsetx = rect.size.width/4;
int offsety= rect.size.height/4;
CGContextMoveToPoint(context, offsetx, offsety);
CGContextAddLineToPoint(context, offsetx*3, offsety*3);
CGContextMoveToPoint(context, offsetx*3, offsety*1);
CGContextAddLineToPoint(context, offsetx*1, offsety*3);
CGContextStrokePath(context);
}
- (void)drawRect:(CGRect)rect
{
switch (self.deleteViewType) {
case UMComActionDeleteViewType_Circle:
[self doDrawCircle:rect];
break;
case UMComActionDeleteViewType_Rectangle:
[self doDrawRectangle:rect];
break;
default:
[self doDrawCircle:rect];
break;
}
}
@end
@@ -0,0 +1,26 @@
//
// UMComActionPickerAddView.h
// UMCommunity
//
// Created by luyiyuan on 14/9/12.
// Copyright (c) 2014年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UMComActionPickerAddView : UIView
@property(nonatomic,assign)BOOL isDashWithBorder;//判断是否边框是否虚线
@end
/**
* 简版的增加图片的控件,增加点击效果
*/
@interface UMComActionPickerBriefAddView : UIButton
@property(nonatomic,readwrite,strong)UIImage* normalAddImg;
@property(nonatomic,readwrite,strong)UIImage* highlightedAddImg;
@end
@@ -0,0 +1,91 @@
//
// UMComActionPickerAddView.m
// UMCommunity
//
// Created by luyiyuan on 14/9/12.
// Copyright (c) 2014年 Umeng. All rights reserved.
//
#import "UMComActionPickerAddView.h"
@implementation UMComActionPickerAddView
- (id)init
{
self = [super init];
if(self)
{
self.backgroundColor = [UIColor clearColor];
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
//rect
if(_isDashWithBorder)
{
CGContextSaveGState(context);
}
CGContextSetRGBStrokeColor(context, 0.7, 0.7, 0.7, 0.7);
CGContextSetLineWidth(context, 1.2);
if (_isDashWithBorder) {
CGFloat lengths[] = {4,4};
CGContextSetLineDash(context, 0, lengths,2);
}
CGContextAddRect(context, self.bounds);
if (_isDashWithBorder) {
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
//+
CGContextSetRGBStrokeColor(context, 0.7, 0.7, 0.7, 0.7);
CGContextSetLineDash(context, 0, NULL, 0);
CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGContextMoveToPoint(context, center.x- self.bounds.size.width/4,center.y);
CGContextAddLineToPoint(context, center.x + self.bounds.size.width/4,center.y);
CGContextMoveToPoint(context, center.x,center.y - self.bounds.size.height/4);
CGContextAddLineToPoint(context, center.x,center.y + self.bounds.size.height/4);
//draw
CGContextStrokePath(context);
}
@end
@implementation UMComActionPickerBriefAddView
-(void) setNormalAddImg:(UIImage *)normalIMG
{
//[self setImage:normalIMG forState:UIControlStateNormal];
[self setBackgroundImage:normalIMG forState:UIControlStateNormal];
}
-(void) setHighlightedAddImg:(UIImage *)highlightedIMG
{
//[self setImage:highlightedIMG forState:UIControlStateHighlighted];
[self setBackgroundImage:highlightedIMG forState:UIControlStateHighlighted];
}
@end
@@ -0,0 +1,39 @@
//
// UMComAddedImageCellView.h
// UMCommunity
//
// Created by luyiyuan on 14/9/17.
// Copyright (c) 2014年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UMComActionDeleteView.h"
@class UMComAddedImageCellView;
@class UMComBriefAddedImageCellView;
typedef void (^DeleteHandle)(UMComAddedImageCellView *iv);
typedef void (^BriefDeleteHandle)(UMComBriefAddedImageCellView *iv);
@interface UMComAddedImageCellView : UIImageView
@property (nonatomic) NSUInteger curIndex;
@property (nonatomic,copy) DeleteHandle handle;
@property (nonatomic,readwrite,assign)UMComActionDeleteViewType deleteViewType;//设置删除的类型
- (void)setIndex:(NSUInteger)index cellPad:(float)cellPad;
- (void)setIndex:(NSUInteger)index cellPad:(float)cellPad imageWidth:(CGFloat)imageWidth;
@end
@interface UMComBriefAddedImageCellView : UIImageView
@property (nonatomic) NSUInteger curIndex;
@property (nonatomic,copy) BriefDeleteHandle handle;
@property (nonatomic,readwrite,assign)UMComActionDeleteViewType deleteViewType;//设置删除的类型
//设置UMComBriefAddedImageCellView的delete的img的图片
@property(nonatomic,readwrite,strong)UIImage* deleteImg;
@end
@@ -0,0 +1,218 @@
//
// UMComAddedImageCellView.m
// UMCommunity
//
// Created by luyiyuan on 14/9/17.
// Copyright (c) 2014年 Umeng. All rights reserved.
//
#import "UMComAddedImageCellView.h"
#import "UMComActionDeleteView.h"
#define IMAGE_WIDTH 73.75
#define YPAD 5
#define TAG_PAD 99
static inline CGRect getRectForIndex(NSUInteger index, float cellPad)
{
return CGRectMake((cellPad+IMAGE_WIDTH)*(index%4)+cellPad, (YPAD+IMAGE_WIDTH)*(index/4)+YPAD, IMAGE_WIDTH, IMAGE_WIDTH);
}
@interface UMComAddedImageCellView()
@property (nonatomic,strong) UMComActionDeleteView *deleteView;
@end
@implementation UMComAddedImageCellView
- (id)initWithImage:(UIImage *)image
{
self = [super initWithImage:image];
if(self)
{
self.userInteractionEnabled = YES;
}
return self;
}
- (void)setIndex:(NSUInteger)index cellPad:(float)cellPad
{
self.curIndex = index;
[self setFrame:getRectForIndex(index,cellPad)];
[self setTag:index + TAG_PAD];
if(!self.deleteView)
{
self.deleteView = [[UMComActionDeleteView alloc] initWithFrame:CGRectMake(self.bounds.size.width - 24, 0, 24, 24)];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteAction:)];
[self.deleteView addGestureRecognizer:tapGesture];
[self addSubview:self.deleteView];
}
}
- (void)setIndex:(NSUInteger)index cellPad:(float)cellPad imageWidth:(CGFloat)imageWidth
{
self.curIndex = index;
[self setFrame:[self getRectForIndex:index cellPad:cellPad imageWidth:imageWidth]];
[self setTag:index + TAG_PAD];
if(!self.deleteView)
{
self.deleteView = [[UMComActionDeleteView alloc] initWithFrame:CGRectMake(self.bounds.size.width - 24, 0, 24, 24)];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteAction:)];
[self.deleteView addGestureRecognizer:tapGesture];
[self addSubview:self.deleteView];
}
}
- (void)setCurIndex:(NSUInteger)curIndex
{
_curIndex = curIndex;
if (!self.deleteView) {
self.deleteView = [[UMComActionDeleteView alloc] initWithFrame:CGRectMake(self.bounds.size.width - 24, 0, 24, 24)];
self.deleteView.deleteViewType = self.deleteViewType;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteAction:)];
[self.deleteView addGestureRecognizer:tapGesture];
[self addSubview:self.deleteView];
}
}
-(CGRect)getRectForIndex:(NSUInteger)index cellPad:(float)cellPad imageWidth:(CGFloat)imageWidth
{
return CGRectMake((cellPad+imageWidth)*(index%4)+cellPad, (YPAD+imageWidth)*(index/4)+YPAD, imageWidth, imageWidth);
}
- (void)deleteAction:(UITapGestureRecognizer *)tapGesture
{
if(self.handle)
{
self.handle(self);
}
}
@end
//点击高亮的图片,只需要生成一次
static UIImage* g_btnImgForBriefAddedImageCell = nil;
@interface UMComBriefAddedImageCellView()
@property (nonatomic,strong) UIView *deleteView;
@property (nonatomic,strong) UIButton* clickButton;
- (void)deleteAction:(UITapGestureRecognizer *)tapGesture;
@end
@implementation UMComBriefAddedImageCellView
+ (UIImage *)buttonImageFromColor:(UIColor *)color{
CGRect rect = CGRectMake(0,0,5,5);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
- (id)initWithImage:(UIImage *)image
{
self = [super initWithImage:image];
if(self)
{
self.userInteractionEnabled = YES;
}
return self;
}
- (void)deleteAction:(UITapGestureRecognizer *)tapGesture
{
if(self.handle)
{
self.handle(self);
}
}
-(void) handleClickButton:(id)target
{
if(self.handle)
{
self.handle(self);
}
}
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
CGRect rc = _deleteView.frame;
if(CGRectContainsPoint(rc,point))
{
return YES;
}
return [super pointInside:point withEvent:event];
}
- (void)setCurIndex:(NSUInteger)curIndex
{
_curIndex = curIndex;
if (!_deleteView) {
//method 1 只是显示一张删除图片
// _deleteView = [[UIImageView alloc] initWithImage:UMComSimpleImageWithImageName(@"um_com_edit_delete")];
// _deleteView.frame = CGRectMake(0, 0, 20, 22);
// _deleteView.center = CGPointMake(0, 0);
//method2 显示点击删除图片的高亮
UIButton* deleteView = [UIButton buttonWithType:UIButtonTypeCustom];
deleteView.frame = CGRectMake(0, 0, 20, 22);
deleteView.center = CGPointMake(0, 0);
if (self.deleteImg) {
[deleteView setImage:self.deleteImg forState:UIControlStateNormal];
}
[deleteView addTarget:self action:@selector(handleClickButton:) forControlEvents:UIControlEventTouchUpInside];
_deleteView = deleteView;
_deleteView.exclusiveTouch = YES;
[self addSubview:deleteView];
//method 1 (没有点击效果)
// UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(deleteAction:)];
// [self addGestureRecognizer:tapGesture];
//method 2 (加入button,有点击效果)
_clickButton = [UIButton buttonWithType:UIButtonTypeCustom];
_clickButton.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
_clickButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_clickButton.exclusiveTouch = YES;
[_clickButton addTarget:self action:@selector(handleClickButton:) forControlEvents:UIControlEventTouchUpInside];
_clickButton.backgroundColor = [UIColor clearColor];
if(!g_btnImgForBriefAddedImageCell)
{
UIColor* btnColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
g_btnImgForBriefAddedImageCell = [UMComBriefAddedImageCellView buttonImageFromColor:btnColor];
}
[_clickButton setBackgroundImage:g_btnImgForBriefAddedImageCell forState:UIControlStateHighlighted];
[self addSubview:_clickButton];
}
}
@end
@@ -0,0 +1,64 @@
//
// UMComAddedImageView.h
// UMCommunity
//
// Created by luyiyuan on 14/9/11.
// Copyright (c) 2014年 Umeng. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "UMComActionDeleteView.h"
typedef void (^PickerHandleAction)(void);
@interface UMComAddedImageView : UIScrollView
@property (nonatomic,copy) PickerHandleAction pickerAction;
@property (nonatomic, assign) CGSize itemSize;
@property (nonatomic,strong,readonly) NSMutableArray *arrayImages;
@property (nonatomic,copy) void (^imagesChangeFinish)(void);
@property (nonatomic,copy) void (^imagesDeleteFinish)(NSInteger index);
@property (nonatomic,copy) void (^actionWithTapImages)(void);
@property (nonatomic,assign,readonly) CGFloat imageSpace;
@property (nonatomic,readwrite,assign) BOOL isAddImgViewShow;//首次判断当前的+的是否显示
@property (nonatomic,readwrite,assign)BOOL isDashWithBorder;//判断边框是否为虚线
@property (nonatomic,readwrite,assign)UMComActionDeleteViewType deleteViewType;//设置删除的类型
@property (nonatomic,readwrite,assign) BOOL isUsingForumMethod;//论坛的方法的显示方式和旧版本的显示不一样
- (void)addImages:(NSArray *)images;
-(void) setIntrinsicSize:(CGSize)size;
@end
/**
* 简版需要用到的AddImageView
*/
@interface UMComBriefAddedImageView : UIScrollView
@property (nonatomic,copy) PickerHandleAction pickerAction;
@property (nonatomic, assign) CGFloat imageSpace;//item之间的距离
@property (nonatomic, assign) CGSize itemSize;//item的size
@property (nonatomic,readwrite,assign)BOOL isDashWithBorder;//判断边框是否为虚线
@property (nonatomic,readwrite,assign) BOOL isAddImgViewShow;//首次判断当前的+的是否显示
@property (nonatomic,readwrite,assign)UMComActionDeleteViewType deleteViewType;//设置删除的类型
@property (nonatomic,strong,readonly) NSMutableArray *arrayImages;
@property (nonatomic,copy) void (^imagesChangeFinish)(void);
@property (nonatomic,copy) void (^imagesDeleteFinish)(NSInteger index);
@property (nonatomic,copy) void (^actionWithTapImages)(void);
//设置内置控件UMComActionPickerBriefAddView的点击效果图片
@property(nonatomic,readwrite,strong)UIImage* normalAddImg;
@property(nonatomic,readwrite,strong)UIImage* highlightedAddImg;
//设置UMComBriefAddedImageCellView的delete的img的图片
@property(nonatomic,readwrite,strong)UIImage* deleteImg;
- (void)addImages:(NSArray *)images;
-(void) setIntrinsicSize:(CGSize)size;
@end