WeChat_Old/博爱微信/Class/Lib/BATools(工具类)/BAKit(工具类)/UIKit/BATextView.m

/*!
 *  @header BAKit
 *          demoTest
 *
 *  @brief  BAKit
 *
 *  @author 博爱
 *  @copyright    Copyright © 2016年 博爱. All rights reserved.
 *  @version    V1.0
 */

/*!
 *
 *          ┌─┐       ┌─┐
 *       ┌──┘ ┴───────┘ ┴──┐
 *       │                 │
 *       │       ───       │
 *       │  ─┬┘       └┬─  │
 *       │                 │
 *       │       ─┴─       │
 *       │                 │
 *       └───┐         ┌───┘
 *           │         │
 *           │         │
 *           │         │
 *           │         └──────────────┐
 *           │                        │
 *           │                        ├─┐
 *           │                        ┌─┘
 *           │                        │
 *           └─┐  ┐  ┌───────┬──┐  ┌──┘
 *             │ ─┤ ─┤       │ ─┤ ─┤
 *             └──┴──┘       └──┴──┘
 *                 神兽保佑
 *                 代码无BUG!
 */

/*
 
 *********************************************************************************
 *
 * 在使用BAKit的过程中如果出现bug请及时以以下任意一种方式联系我，我会及时修复bug
 *
 * QQ     : 可以添加SDAutoLayout群 497140713 在这里找到我(博爱1616【137361770】)
 * 微博    : 博爱1616
 * Email  : 137361770@qq.com
 * GitHub : https://github.com/boai
 * 博客园  : http://www.cnblogs.com/boai/
 *********************************************************************************
 
 */

#import "BATextView.h"

@implementation BATextView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self addObserver];
    }
    return self;
}

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

- (void)addObserver
{
    // 注册通知
    [BA_Noti addObserver:self selector:@selector(didBeginEditing:) name:UITextViewTextDidBeginEditingNotification object:self];
    [BA_Noti addObserver:self selector:@selector(didEndEditing:) name:UITextViewTextDidEndEditingNotification object:self];
    [BA_Noti addObserver:self selector:@selector(terminate:) name:UIApplicationWillTerminateNotification object:BASharedApplication];
}

- (void)setPlaceholder:(NSString *)placeholder
{
    _placeholder = placeholder;
    self.text = placeholder;
    self.textColor = self.placeholderTextColor;
}

- (void)terminate:(NSNotification *)notification
{
    // 移除通知
    [BA_Noti removeObserver:self];
}

- (void)didBeginEditing:(NSNotification *)notification
{
    if ([self.text isEqualToString:self.placeholder])
    {
        BALog(@"开始编辑！")
        self.text = @"";
        self.textColor = [UIColor blackColor];
    }
}

- (void)didEndEditing:(NSNotification *)notification
{
    if (self.text.length < 1)
    {
        BALog(@"结束编辑！")
        self.text = self.placeholder;
        self.textColor = [UIColor grayColor];
    }
}

@end
