textView的提醒文字

如果我们想提交一些备注信息,会想到用textFiled和textView两种控件去实现

1.提醒文字是textFiled的特有属性,但是textFiled显示文本只有一行,不能实现我们输入较多文字的情况

2.textView可以自动适配多文字输入,但是没有提醒文字,这也不符合我们设计的需求

下面就有一种解决方法,话不多说,直接上代码

#import "YSCreateScheduleRemarkView.h"

#import "Masonry.h"

 

@interface YSCreateScheduleRemarkView ()

 

@end

 

@implementation YSCreateScheduleRemarkView

 

- (instancetype)initWithFrame:(CGRect)frame {

 

    if (self = [super initWithFrame:frame]) {

        

        [self initUI];

    }

    

    return self;

}

 

- (void)initUI {

 

    self backgroundColor = [UIColor whiteColor];

    _textView = [[UITextView alloc] init];

    _textView.font = [UIFont systemFontOfSize:15];

    [self addSubview:_textView];

    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {

        

        make.top.mas_equalTo(self.mas_top);

        make.left.mas_equalTo(self.mas_left).offset(10);

        make.bottom.mas_equalTo(self.mas_bottom);

        make.right.mas_equalTo(self.mas_right).offset(-10);

    }];

}

 

- (void)setplaceholder:(NSString *)placeholder {

 

    UILabel *placeholderLabel = [[UILabel alloc] init];

    placeholderLabel.text = placeholder;

    placeholderLabel.numberOfLines = 1;

    placeholderLabel.textColor = [UIColor lightGrayColor];

    [placeholderLabel sizeToFit];

    placeholderLabel.font = _textView.font;

    [_textView addSubview:placeholderLabel];

    [_textView setValue:placeholderLabel forKey:@"_placeholderLabel"];

}

 

@end

 

#import "ViewController.h"

#import "YSCreateScheduleRemarkView.h"

 

@interface ViewController ()<UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, UITextViewDelegate>

{

    UITableView *table;

}

@property (nonatomic, strong) YSCreateScheduleRemarkView *createScheduleRemarkView;

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor = [UIColorwhiteColor];

    table = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];

    table.delegate = self;

    table.dataSource = self;

    [self.view addSubview:table];

    [table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"CreateScheduleCell"];

    

    

}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return  4;

}

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return 0.01;

}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    return 135;

}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

    

    _createScheduleRemarkView = [[YSCreateScheduleRemarkView alloc] init];

    _createScheduleRemarkView.textView.delegate = self;

    [_createScheduleRemarkView setplaceholder:@"备注"];

    return _createScheduleRemarkView;

}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CreateScheduleCell"];

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CreateScheduleCell"];

    cell.textLabel.text = @"12111";

    return cell;

}

- (void)textViewDidBeginEditing:(UITextView *)textView {

    

    [self showKeyboardManager:1]:

}

 

- (void)textViewDidEndEditing:(UITextView *)textView {

    

    [self showKeyboardManager:0];

}

 

- (void)showKeyboardManager:(NSInteger)integer {

    

    [UIView animateWithDuration:0.2f animations:^{

        

        table.frame = CGRectMake(0, integer == 1 ? -44*4 : 0, 375, 667);

    }];

}

 

转载于:https://www.cnblogs.com/lcl15/p/6240071.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值