1、attributedPlaceholder
//
// TGTextField.h
//
// Created by targetcloud on 2017/3/7.
// Copyright © 2017年 targetcloud. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TGTextField : UITextField
@end
//
// TGTextField.m
//
// Created by targetcloud on 2017/3/7.
// Copyright © 2017年 targetcloud. All rights reserved.
//
#import "TGTextField.h"
@implementation TGTextField
- (void)awakeFromNib{
[super awakeFromNib];
self.tintColor = [UIColor whiteColor];
[self addTarget:self action:@selector(textBegin) forControlEvents:UIControlEventEditingDidBegin];
[self addTarget:self action:@selector(textEnd) forControlEvents:UIControlEventEditingDidEnd];
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder attributes:attrs];
}
- (void)textBegin{
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
self.attributedPlaceholder = [[NSAttributedString alloc] initWithString:self.placeholder attributes:attrs];
}
-