HLEditTextView以后用,不想重复写代码

#import 

@interface HLEditTextView : UITextView

@property(nonatomic,copy)NSString *noticeStr;

@end
#import "HLEditTextView.h"

@interface HLEditTextView ()

@property(nonatomic,strong)UILabel *noticeLabel;

@end

@implementation HLEditTextView

-(id)init
{
    if (self = [super init]) {
        [self setupUI];
    }
    return self;
}

#pragma mark =================UI================

-(void)setupUI
{
    _noticeLabel = [[UILabel alloc] init];
    _noticeLabel.font = [UIFont systemFontOfSize:15];
    _noticeLabel.textColor = [UIColor grayColor];
    [self addSubview:_noticeLabel];
    
    self.delegate = self;
}

-(void)layoutSubviews
{
    _noticeLabel.frame = CGRectMake(15, 0,self.bounds.size.width, 30);
}

-(void)setNoticeStr:(NSString *)noticeStr
{
    _noticeStr = noticeStr;
    _noticeLabel.text =  _noticeStr;
}

#pragma mark =================Delegate=================

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    _noticeLabel.hidden = YES;
}

- (void)textViewDidChange:(UITextView *)textView
{
    HLLOG(@"%@",textView.text);
    if ([textView.text isEqualToString:@""]) {
        _noticeLabel.hidden = NO;
    }
    else
    {
        _noticeLabel.hidden = YES;
    }
}

@end

你可能感兴趣的:(HLEditTextView以后用,不想重复写代码)