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

#import <UIKit/UIKit.h>

@interface HLEditTextView : UITextView

@property(nonatomic,copy)NSString *noticeStr;

@end
#import "HLEditTextView.h"

@interface HLEditTextView ()<UITextViewDelegate>

@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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容