2019-01-03 18:03:44 +08:00
|
|
|
//
|
|
|
|
|
// CRBoxInputCell.m
|
|
|
|
|
// CaiShenYe
|
|
|
|
|
//
|
|
|
|
|
// Created by Chobits on 2019/1/3.
|
|
|
|
|
// Copyright © 2019 Chobits. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "CRBoxInputCell.h"
|
|
|
|
|
#import "Masonry.h"
|
|
|
|
|
|
|
|
|
|
@interface CRBoxInputCell ()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-01-04 15:28:43 +08:00
|
|
|
|
|
|
|
|
@property (strong, nonatomic) UILabel *valueLabel;
|
|
|
|
|
@property (strong, nonatomic) CABasicAnimation *opacityAnimation;
|
2019-01-06 18:59:10 +08:00
|
|
|
@property (strong, nonatomic) UIView *customSecurityView;
|
2019-01-04 15:28:43 +08:00
|
|
|
|
2019-01-03 18:03:44 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation CRBoxInputCell
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
|
|
|
|
|
|
if (self) {
|
2019-01-07 14:46:50 +08:00
|
|
|
[self createUIBase];
|
2019-01-03 18:03:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 15:28:43 +08:00
|
|
|
- (void)initPara
|
2019-01-03 18:03:44 +08:00
|
|
|
{
|
|
|
|
|
self.ifNeedCursor = YES;
|
|
|
|
|
self.userInteractionEnabled = NO;
|
2019-01-04 15:28:43 +08:00
|
|
|
}
|
|
|
|
|
|
2019-01-07 14:46:50 +08:00
|
|
|
- (void)createUIBase
|
2019-01-04 15:28:43 +08:00
|
|
|
{
|
|
|
|
|
[self initPara];
|
2019-01-03 18:03:44 +08:00
|
|
|
|
|
|
|
|
_valueLabel = [UILabel new];
|
|
|
|
|
_valueLabel.font = [UIFont systemFontOfSize:38];
|
|
|
|
|
[self.contentView addSubview:_valueLabel];
|
|
|
|
|
[_valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.centerX.offset(0);
|
|
|
|
|
make.centerY.offset(0);
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
_cursorView = [UIView new];
|
|
|
|
|
[self.contentView addSubview:_cursorView];
|
|
|
|
|
[_cursorView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.centerX.offset(0);
|
2019-01-07 12:30:15 +08:00
|
|
|
make.centerY.offset(0);
|
2019-01-03 18:03:44 +08:00
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
[self initCellProperty];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)initCellProperty
|
|
|
|
|
{
|
|
|
|
|
CRBoxInputCellProperty *cellProperty = [CRBoxInputCellProperty new];
|
|
|
|
|
self.boxInputCellProperty = cellProperty;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 16:51:30 +08:00
|
|
|
- (void)valueLabelLoadData
|
|
|
|
|
{
|
|
|
|
|
_valueLabel.hidden = NO;
|
2019-01-04 20:07:30 +08:00
|
|
|
[self hideCustomSecurityView];
|
2019-01-04 16:51:30 +08:00
|
|
|
|
2019-01-04 20:07:30 +08:00
|
|
|
BOOL hasOriginValue = self.boxInputCellProperty.originValue && self.boxInputCellProperty.originValue.length > 0;
|
|
|
|
|
if (hasOriginValue) {
|
2019-01-04 16:51:30 +08:00
|
|
|
if (self.boxInputCellProperty.ifShowSecurity) {
|
2019-01-07 15:50:20 +08:00
|
|
|
if (self.boxInputCellProperty.securityType == CRBoxSecuritySymbolType) {
|
2019-01-04 16:51:30 +08:00
|
|
|
_valueLabel.text = self.boxInputCellProperty.securitySymbol;
|
2019-01-07 15:50:20 +08:00
|
|
|
}else if (self.boxInputCellProperty.securityType == CRBoxSecurityCustomViewType) {
|
2019-01-04 16:51:30 +08:00
|
|
|
_valueLabel.hidden = YES;
|
2019-01-04 18:43:36 +08:00
|
|
|
[self showCustomSecurityView];
|
2019-01-04 16:51:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
_valueLabel.text = self.boxInputCellProperty.originValue;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
_valueLabel.text = @"";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Custom security view
|
2019-01-04 18:43:36 +08:00
|
|
|
- (void)showCustomSecurityView
|
2019-01-04 16:51:30 +08:00
|
|
|
{
|
2019-01-04 18:43:36 +08:00
|
|
|
if (!self.customSecurityView.superview) {
|
|
|
|
|
[self.contentView addSubview:self.customSecurityView];
|
|
|
|
|
[self.customSecurityView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.edges.mas_equalTo(UIEdgeInsetsZero);
|
|
|
|
|
}];
|
2019-01-04 16:51:30 +08:00
|
|
|
}
|
2019-01-04 18:43:36 +08:00
|
|
|
|
|
|
|
|
self.customSecurityView.alpha = 1;
|
2019-01-04 16:51:30 +08:00
|
|
|
}
|
|
|
|
|
|
2019-01-04 18:43:36 +08:00
|
|
|
- (void)hideCustomSecurityView
|
|
|
|
|
{
|
|
|
|
|
self.customSecurityView.alpha = 0;
|
2019-01-04 16:51:30 +08:00
|
|
|
}
|
|
|
|
|
|
2019-01-03 18:03:44 +08:00
|
|
|
#pragma mark - Setter & Getter
|
2019-01-04 16:51:30 +08:00
|
|
|
- (CABasicAnimation *)opacityAnimation
|
|
|
|
|
{
|
|
|
|
|
if (!_opacityAnimation) {
|
|
|
|
|
_opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
|
|
|
|
|
_opacityAnimation.fromValue = @(1.0);
|
|
|
|
|
_opacityAnimation.toValue = @(0.0);
|
|
|
|
|
_opacityAnimation.duration = 0.9;
|
|
|
|
|
_opacityAnimation.repeatCount = HUGE_VALF;
|
|
|
|
|
_opacityAnimation.removedOnCompletion = YES;
|
|
|
|
|
_opacityAnimation.fillMode = kCAFillModeForwards;
|
|
|
|
|
_opacityAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _opacityAnimation;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-03 18:03:44 +08:00
|
|
|
- (void)setSelected:(BOOL)selected
|
|
|
|
|
{
|
|
|
|
|
if (selected) {
|
|
|
|
|
self.layer.borderColor = self.boxInputCellProperty.cellBorderColorSelected.CGColor;
|
2019-01-07 12:56:47 +08:00
|
|
|
self.backgroundColor = self.boxInputCellProperty.cellBgColorSelected;
|
2019-01-03 18:03:44 +08:00
|
|
|
}else{
|
2019-03-20 13:49:22 +08:00
|
|
|
BOOL hasFill = _valueLabel.text.length > 0 ? YES : NO;
|
|
|
|
|
UIColor *cellBorderColor = self.boxInputCellProperty.cellBorderColorNormal;
|
|
|
|
|
UIColor *cellBackgroundColor = self.boxInputCellProperty.cellBgColorNormal;
|
|
|
|
|
if (hasFill) {
|
|
|
|
|
if (self.boxInputCellProperty.cellBorderColorFilled) {
|
|
|
|
|
cellBorderColor = self.boxInputCellProperty.cellBorderColorFilled;
|
|
|
|
|
}
|
|
|
|
|
if (self.boxInputCellProperty.cellBgColorFilled) {
|
|
|
|
|
cellBackgroundColor = self.boxInputCellProperty.cellBgColorFilled;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.layer.borderColor = cellBorderColor.CGColor;
|
|
|
|
|
self.backgroundColor = cellBackgroundColor;
|
2019-01-03 18:03:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_ifNeedCursor) {
|
|
|
|
|
if (selected) {
|
|
|
|
|
_cursorView.hidden= NO;
|
|
|
|
|
[_cursorView.layer addAnimation:self.opacityAnimation forKey:CRBoxCursoryAnimationKey];
|
|
|
|
|
}else{
|
|
|
|
|
_cursorView.hidden= YES;
|
|
|
|
|
[_cursorView.layer removeAnimationForKey:CRBoxCursoryAnimationKey];
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
_cursorView.hidden= YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setBoxInputCellProperty:(CRBoxInputCellProperty *)boxInputCellProperty
|
|
|
|
|
{
|
|
|
|
|
_boxInputCellProperty = boxInputCellProperty;
|
|
|
|
|
|
|
|
|
|
_cursorView.backgroundColor = boxInputCellProperty.cellCursorColor;
|
2019-01-07 12:30:15 +08:00
|
|
|
[_cursorView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.width.mas_equalTo(boxInputCellProperty.cellCursorWidth);
|
|
|
|
|
make.height.mas_equalTo(boxInputCellProperty.cellCursorHeight);
|
|
|
|
|
}];
|
2019-01-03 18:03:44 +08:00
|
|
|
self.layer.cornerRadius = boxInputCellProperty.cornerRadius;
|
|
|
|
|
self.layer.borderWidth = boxInputCellProperty.borderWidth;
|
|
|
|
|
|
|
|
|
|
if (boxInputCellProperty.cellFont) {
|
|
|
|
|
_valueLabel.font = boxInputCellProperty.cellFont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (boxInputCellProperty.cellTextColor) {
|
|
|
|
|
_valueLabel.textColor = boxInputCellProperty.cellTextColor;
|
|
|
|
|
}
|
2019-01-04 15:28:43 +08:00
|
|
|
|
|
|
|
|
[self valueLabelLoadData];
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-04 16:51:30 +08:00
|
|
|
- (UIView *)customSecurityView
|
2019-01-03 18:03:44 +08:00
|
|
|
{
|
2019-01-04 16:51:30 +08:00
|
|
|
if (!_customSecurityView) {
|
2019-01-06 19:40:28 +08:00
|
|
|
_customSecurityView = [self createCustomSecurityView];
|
2019-01-03 18:03:44 +08:00
|
|
|
}
|
|
|
|
|
|
2019-01-04 16:51:30 +08:00
|
|
|
return _customSecurityView;
|
2019-01-03 18:03:44 +08:00
|
|
|
}
|
|
|
|
|
|
2019-01-06 19:40:28 +08:00
|
|
|
#pragma mark - You can rewrite
|
|
|
|
|
- (UIView *)createCustomSecurityView
|
|
|
|
|
{
|
|
|
|
|
UIView *customSecurityView = [UIView new];
|
|
|
|
|
customSecurityView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
|
|
|
|
|
// circleView
|
|
|
|
|
static CGFloat circleViewWidth = 20;
|
|
|
|
|
UIView *circleView = [UIView new];
|
|
|
|
|
circleView.backgroundColor = [UIColor orangeColor];
|
|
|
|
|
circleView.layer.cornerRadius = circleViewWidth / 2;
|
|
|
|
|
[customSecurityView addSubview:circleView];
|
|
|
|
|
[circleView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.width.height.mas_equalTo(circleViewWidth);
|
|
|
|
|
make.centerX.offset(0);
|
|
|
|
|
make.centerY.offset(0);
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
return customSecurityView;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-03 18:03:44 +08:00
|
|
|
@end
|