-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathInputOnlyTextPlainCell.m
executable file
·60 lines (55 loc) · 2.12 KB
/
InputOnlyTextPlainCell.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// InputOnlyTextPlainCell.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-26.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "InputOnlyTextPlainCell.h"
@interface InputOnlyTextPlainCell ()
@property (strong, nonatomic) UITextField *textField;
@property (strong, nonatomic) NSString *phStr, *valueStr;
@property (assign,nonatomic) BOOL isSecure;
@end
@implementation InputOnlyTextPlainCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.selectionStyle = UITableViewCellSelectionStyleNone;
if (!_textField) {
_textField = [UITextField new];
_textField.backgroundColor = [UIColor clearColor];
_textField.borderStyle = UITextBorderStyleNone;
_textField.font = [UIFont systemFontOfSize:16];
[_textField addTarget:self action:@selector(textValueChanged:) forControlEvents:UIControlEventEditingChanged];
_textField.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.contentView addSubview:_textField];
[_textField mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(kPaddingLeftWidth);
make.right.offset(-kPaddingLeftWidth);
make.centerY.equalTo(self.contentView);
make.height.mas_equalTo(30);
}];
}
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
_textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:_phStr? _phStr: @"" attributes:@{NSForegroundColorAttributeName: kColor999}];
_textField.text = _valueStr;
_textField.secureTextEntry = _isSecure;
}
- (void)configWithPlaceholder:(NSString *)phStr valueStr:(NSString *)valueStr secureTextEntry:(BOOL)isSecure{
self.phStr = phStr;
self.valueStr = valueStr;
self.isSecure = isSecure;
}
- (void)textValueChanged:(id)sender {
if (self.textValueChangedBlock) {
self.textValueChangedBlock(self.textField.text);
}
}
@end