123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- #import "XLsn0wInputBox.h"
- #import "Masonry.h"
- #import "ConfigHeader.h"
- #define XLsn0wInputBoxWidth 300
- #define XLsn0wInputBoxHeight 240
- #define HexColor(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
- #define HexColorAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]
- @interface XLsn0wInputBox ()
- /** 确认按钮回调 */
- @property (nonatomic, copy) confirmCallback confirmBlock;
- /** 蒙版 */
- @property (nonatomic, strong) UIButton *maskView;
- @end
- @implementation XLsn0wInputBox
- - (instancetype)init {
- if (self = [super init]) {
- }
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- [self initUI];
- }
- return self;
- }
- - (void)initUI {
- self.maskView = [[UIButton alloc] initWithFrame:[UIScreen mainScreen].bounds];
- self.maskView.backgroundColor = [UIColor blackColor];
- self.maskView.layer.opacity = 0.3;
- // [[self.maskView rac_signalForControlEvents:UIControlEventTouchUpInside]
- // subscribeNext:^(__kindof UIControl * _Nullable x) {
- // [self hide];
- // }];
- [self.maskView addTarget:self action:@selector(hide) forControlEvents:(UIControlEventTouchUpInside)];
-
- self.backgroundColor = UIColor.whiteColor;
- // [self xlsn0w_addCornerRadius:4];
- self.layer.cornerRadius = 4;
- self.layer.masksToBounds = YES;
- self.frame = CGRectMake(0, 0, XLsn0wInputBoxWidth, XLsn0wInputBoxHeight);
- self.center = CGPointMake(self.maskView.center.x, self.maskView.frame.size.height * 0.4);
-
- _title = [[UILabel alloc] init];
- [self addSubview:_title];
- [_title mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self);
- make.top.mas_equalTo(16);
- }];
- // [_title addTextFont:[UIFont systemFontOfSize:16] textColor:HexColor(@"#333333")];
- _title.textColor = HexColor(0x333333);
- _title.font = AppSystemFont(16);
-
- _inputTextView = [[JHHolderTextView alloc] initWithFrame:CGRectMake(22, 48, self.frame.size.width-44, self.frame.size.height-77-48)];
- [self addSubview:_inputTextView];
- [_inputTextView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(22);
- make.right.mas_equalTo(-22);
- make.top.mas_equalTo(48);
- make.bottom.mas_equalTo(-70);
- }];
- _inputTextView.layer.borderWidth = 1;
- _inputTextView.layer.borderColor = HexColor(0xE1E1E1).CGColor;
- _inputTextView.layer.cornerRadius = 4;
- _inputTextView.layer.masksToBounds = YES;
- // _inputTextView.holder = @"填写\"震\"内容或点击\"确定\"直接震";
- _inputTextView.limitCount = 50;
- _cancelBtn = [UIButton new];
- [self addSubview:_cancelBtn];
- [_cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(0);
- make.left.mas_equalTo(0);
- make.width.mas_equalTo(XLsn0wInputBoxWidth/2);
- make.height.mas_equalTo(55);
- }];
- [_cancelBtn setTitle:@"取消" forState:(UIControlStateNormal)];
- [_cancelBtn setTitleColor:HexColor(0x666666) forState:(UIControlStateNormal)];
- _cancelBtn.titleLabel.font = [UIFont systemFontOfSize:16];
- // [[_cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside]
- // subscribeNext:^(__kindof UIControl * _Nullable x) {
- // [self hide];
- // }];
- [_cancelBtn addTarget:self action:@selector(hide) forControlEvents:(UIControlEventTouchUpInside)];
- _cancelBtn.backgroundColor = AppWhiteColor;
-
- ButtonHighlighted(_cancelBtn, HexColorAlpha(0x000000, 0.1))
-
- _confirmBtn = [UIButton new];
- [self addSubview:_confirmBtn];
- [_confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.width.mas_equalTo(XLsn0wInputBoxWidth/2);
- make.height.mas_equalTo(55);
- }];
- [_confirmBtn setTitle:@"确认" forState:(UIControlStateNormal)];
- [_confirmBtn setTitleColor:HexColor(0x4E8AFF) forState:(UIControlStateNormal)];
- _confirmBtn.titleLabel.font = [UIFont systemFontOfSize:16];
- // [[_confirmBtn rac_signalForControlEvents:UIControlEventTouchUpInside]
- // subscribeNext:^(__kindof UIControl * _Nullable x) {
- // [self confirmAction];
- // }];
- [_confirmBtn addTarget:self action:@selector(confirmAction) forControlEvents:(UIControlEventTouchUpInside)];
- _confirmBtn.backgroundColor = AppWhiteColor;
- ButtonHighlighted(_confirmBtn, HexColorAlpha(0x000000, 0.1))
-
- UIView* horizontalLine = [[UIView alloc] init];
- [self addSubview:horizontalLine];
- [horizontalLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.bottom.mas_equalTo(-55);
- make.width.mas_equalTo(XLsn0wInputBoxWidth);
- make.height.mas_equalTo(1);
- }];
- horizontalLine.backgroundColor = HexColorAlpha(0x000000, 0.1);
-
- UIView* verticalLine = [[UIView alloc] init];
- [self addSubview:verticalLine];
- [verticalLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self);
- make.bottom.mas_equalTo(0);
- make.width.mas_equalTo(1);
- make.height.mas_equalTo(55);
- }];
- verticalLine.backgroundColor = HexColorAlpha(0x000000, 0.1);
- }
- #pragma mark - 设置控件圆角
- - (void)setCornerRadius:(UIView *)view {
- if (self.radius) {
- view.layer.cornerRadius = self.radius;
- } else {
- view.layer.cornerRadius = 5.0;
- }
-
- view.layer.masksToBounds = YES;
- }
- - (void)setPlaceholder:(NSString *)placeholder {
- _placeholder = [placeholder copy];
- // self.inputTextView.placeholder = self.placeholder;
- // NSMutableAttributedString *placeholderString = [[NSMutableAttributedString alloc] initWithString:placeholder attributes:@{NSForegroundColorAttributeName : [UIColor lightGrayColor]}];
- // self.inputTextView.attributedPlaceholder = placeholderString;
- // Ivar ivar = class_getInstanceVariable([UITextView class], "_placeholderLabel");
- // UILabel *placehoderLabel = object_getIvar(self.inputTextView, ivar);
- // placehoderLabel.text = placeholder;
- _inputTextView.holder = placeholder;
- // _inputTextView.limitCount = 50;
- }
- - (void)show {
- [UIView animateWithDuration:0.2 animations:^{
- [kKeyWindow addSubview:self.maskView];
- [kKeyWindow addSubview:self];
- [self->_inputTextView.textView becomeFirstResponder];
- } completion:^(BOOL finished) {}];
- }
- - (void)exitKeyboard {
- [self endEditing:YES];
- }
- - (void)hide {
- [UIView animateWithDuration:0.2 animations:^{
- [self exitKeyboard];
- [self removeFromSuperview];
- [self.maskView removeFromSuperview];
- } completion:^(BOOL finished) {
- }];
- }
- #pragma mark - 接收传过来的block
- - (void)confirmBtnClickBlock:(confirmCallback)block {
- self.confirmBlock = block;
- }
- #pragma mark - 点击确认按钮
- - (void)confirmAction {
- [self hide];
- if (self.confirmBlock) {
- self.confirmBlock(self.inputTextView.text);
- }
- }
- @end
|