|
|
|
|
//
|
|
|
|
|
// WTMeCell.m
|
|
|
|
|
// WTBaiSiBuDeJie
|
|
|
|
|
//
|
|
|
|
|
// Created by yuklng on 2017/1/11.
|
|
|
|
|
// Copyright © 2017年 yuklng. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "WTMeCell.h"
|
|
|
|
|
#import "UIView+Extension.h"
|
|
|
|
|
|
|
|
|
|
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
|
|
|
|
|
#define RGB(r,g,b) RGBA(r,g,b,1.0f)
|
|
|
|
|
|
|
|
|
|
@interface WTMeCell ()<UITextFieldDelegate>
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation WTMeCell{
|
|
|
|
|
UIView* Main_View; //容器
|
|
|
|
|
UIView* _InputView; //二级容器
|
|
|
|
|
UILabel* _TypeLable; //标签label
|
|
|
|
|
|
|
|
|
|
NSInteger TextFieldLength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
|
|
|
|
if (self) {
|
|
|
|
|
self.textLabel.textColor = [UIColor darkGrayColor];
|
|
|
|
|
// self.textLabel.font = [UIFont systemFontOfSize:14];
|
|
|
|
|
// self.regular_text = @"^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$";
|
|
|
|
|
|
|
|
|
|
self.regular_text = @"";
|
|
|
|
|
_type_text = @"WTMeCell";
|
|
|
|
|
_cell_Identifier = reuseIdentifier;
|
|
|
|
|
TextFieldLength = 11;
|
|
|
|
|
|
|
|
|
|
[self createItems];
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark 视图构建方法
|
|
|
|
|
-(void)createItems {
|
|
|
|
|
|
|
|
|
|
if(!Main_View){
|
|
|
|
|
[self.contentView addSubview:({
|
|
|
|
|
UIView* Cell_View =[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
|
|
|
|
|
Cell_View.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
Main_View =Cell_View;
|
|
|
|
|
Cell_View;
|
|
|
|
|
})];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Main_View addSubview:[self createInputView:@""]];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(UIView*)createInputView:(NSString*)type_text{
|
|
|
|
|
NSInteger view_height =Main_View.height;
|
|
|
|
|
NSInteger view_width =Main_View.width;
|
|
|
|
|
NSInteger view_x =0;
|
|
|
|
|
NSInteger view_y =0; //subscript*view_height
|
|
|
|
|
|
|
|
|
|
UIView* Input_view =[[UIView alloc] init];
|
|
|
|
|
Input_view.x =view_x;
|
|
|
|
|
Input_view.y =view_y;
|
|
|
|
|
Input_view.width =view_width;
|
|
|
|
|
Input_view.height =view_height;
|
|
|
|
|
|
|
|
|
|
_InputView =Input_view;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Input_view addSubview:({
|
|
|
|
|
UILabel* Input_type_view =[[UILabel alloc] init];
|
|
|
|
|
Input_type_view.x =10;
|
|
|
|
|
Input_type_view.y =0;
|
|
|
|
|
Input_type_view.width =Input_view.width/3;
|
|
|
|
|
Input_type_view.height =Input_view.height;
|
|
|
|
|
Input_type_view.textAlignment =NSTextAlignmentLeft;
|
|
|
|
|
Input_type_view.text =type_text;
|
|
|
|
|
|
|
|
|
|
UIFont* newFont =[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
|
|
|
|
|
UIFontDescriptor* ctfFont =newFont.fontDescriptor;
|
|
|
|
|
NSNumber* fontString =[ctfFont objectForKey:@"NSFontSizeAttribute"];
|
|
|
|
|
|
|
|
|
|
// NSLog(@"当前使用的字体是%@",fontString);
|
|
|
|
|
Input_type_view.font =[UIFont systemFontOfSize:fontString.floatValue];
|
|
|
|
|
|
|
|
|
|
_TypeLable =Input_type_view;
|
|
|
|
|
|
|
|
|
|
Input_type_view;
|
|
|
|
|
})];
|
|
|
|
|
|
|
|
|
|
[Input_view addSubview:({
|
|
|
|
|
UITextField* Input_type_view =[[UITextField alloc] init];
|
|
|
|
|
Input_type_view.x =Input_view.width/3;
|
|
|
|
|
Input_type_view.y =0;
|
|
|
|
|
Input_type_view.width =Input_view.width;
|
|
|
|
|
Input_type_view.height =Input_view.height;
|
|
|
|
|
Input_type_view.placeholder =@"";
|
|
|
|
|
Input_type_view.tag =50;
|
|
|
|
|
Input_type_view.delegate =self;
|
|
|
|
|
|
|
|
|
|
UIFont* newFont =[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
|
|
|
|
|
UIFontDescriptor* ctfFont =newFont.fontDescriptor;
|
|
|
|
|
NSNumber* fontString =[ctfFont objectForKey:@"NSFontSizeAttribute"];
|
|
|
|
|
|
|
|
|
|
// NSLog(@"当前使用的字体是%@",fontString);
|
|
|
|
|
Input_type_view.font =[UIFont systemFontOfSize:fontString.floatValue-2];
|
|
|
|
|
|
|
|
|
|
_InputText =Input_type_view;
|
|
|
|
|
|
|
|
|
|
Input_type_view;
|
|
|
|
|
})];
|
|
|
|
|
|
|
|
|
|
return Input_view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark 更新视图
|
|
|
|
|
-(void)upDateInputView{
|
|
|
|
|
NSInteger view_height =Main_View.height;
|
|
|
|
|
NSInteger view_width =Main_View.width;
|
|
|
|
|
NSInteger view_x =0;
|
|
|
|
|
NSInteger view_y =0;
|
|
|
|
|
|
|
|
|
|
_InputView.x =view_x;
|
|
|
|
|
_InputView.y =view_y;
|
|
|
|
|
_InputView.width =view_width;
|
|
|
|
|
_InputView.height =view_height;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_TypeLable.height =_InputView.height;
|
|
|
|
|
|
|
|
|
|
_InputText.height =_InputView.height;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)setTitle:(NSString *)title cellText:(NSString*)cell_text placeholder:(NSString*)placeholder{
|
|
|
|
|
|
|
|
|
|
_TypeLable.text = title;
|
|
|
|
|
_InputText.text = cell_text;
|
|
|
|
|
_InputText.placeholder =placeholder;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark UITextFieldDelegate
|
|
|
|
|
- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string{
|
|
|
|
|
NSMutableString* now_text =[NSMutableString stringWithFormat:@"%@", textField.text];
|
|
|
|
|
if (range.length>0) {
|
|
|
|
|
[now_text deleteCharactersInRange:range];
|
|
|
|
|
}else{
|
|
|
|
|
[now_text insertString:string atIndex:range.location];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (textField.text.length>=TextFieldLength && ![string isEqualToString:@""]) {
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_now_text =now_text;
|
|
|
|
|
|
|
|
|
|
// NSLog(@"length :%lu %@ range-location :%lu range-length :%lu",now_text.length,now_text,(unsigned long)range.location,(unsigned long)range.length);
|
|
|
|
|
|
|
|
|
|
if ([self validateNumber:now_text]||[self.regular_text isEqualToString:@""]) {
|
|
|
|
|
_isBool =YES;
|
|
|
|
|
}else{
|
|
|
|
|
_isBool =NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (self.block) {
|
|
|
|
|
self.block (nil,self);
|
|
|
|
|
}
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)layoutSubviews {
|
|
|
|
|
[super layoutSubviews];
|
|
|
|
|
|
|
|
|
|
NSInteger margin =10;
|
|
|
|
|
|
|
|
|
|
Main_View.x =margin;
|
|
|
|
|
Main_View.y =0;
|
|
|
|
|
Main_View.width =self.contentView.frame.size.width-20;
|
|
|
|
|
Main_View.height =self.contentView.frame.size.height;
|
|
|
|
|
|
|
|
|
|
[self upDateInputView];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark 正则表达式判断
|
|
|
|
|
-(BOOL)validateNumber:(NSString *)text
|
|
|
|
|
{
|
|
|
|
|
NSPredicate *numberPre = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",self.regular_text];
|
|
|
|
|
return [numberPre evaluateWithObject:text];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark set
|
|
|
|
|
-(void)setTextFieldLength:(NSInteger)length{
|
|
|
|
|
TextFieldLength =length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|