iOS 客户端学习-UITextView
来源:互联网 发布:visio 网络拓扑图 注意 编辑:程序博客网 时间:2024/05/17 02:19
1.UITextView中添加placeholder
创建GCPlaceholderTextView类,如下所示,使用方法,创建公共方法
+(void)setTextViewByTextView:(GCPlaceholderTextView*)textView placeholder: (NSString*)placeholder{
textView.placeholderColor = [UIColorlightGrayColor];
textView.placeholder =NSLocalizedString(placeholder,);
}
在页面调用方法如下:
[UtilssetTextViewByTextView:self.textView placeholder:@""];
GCPlaceholderTextView.h文件
#import <UIKit/UIKit.h>
@interface GCPlaceholderTextView : UITextView
@property(nonatomic,strong) NSString *placeholder;
@property (nonatomic,strong) UIColor *realTextColorUI_APPEARANCE_SELECTOR;
@property (nonatomic,strong) UIColor *placeholderColorUI_APPEARANCE_SELECTOR;
@end
GCPlaceholderTextView.m文件
#import "GCPlaceholderTextView.h"
@interface GCPlaceholderTextView ()
@property (unsafe_unretained,nonatomic, readonly)NSString* realText;
- (void) beginEditing:(NSNotification*) notification;
- (void) endEditing:(NSNotification*) notification;
@end
@implementation GCPlaceholderTextView
@synthesize realTextColor;
@synthesize placeholder;
@synthesize placeholderColor;
#pragma mark -
#pragma mark Initialisation
- (id) initWithFrame:(CGRect)frame {
if ((self = [superinitWithFrame:frame])) {
[selfawakeFromNib];
}
return self;
}
- (void)awakeFromNib {
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(beginEditing:)name:UITextViewTextDidBeginEditingNotificationobject:self];
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(endEditing:)name:UITextViewTextDidEndEditingNotificationobject:self];
self.realTextColor =self.textColor;
self.placeholderColor = [UIColorlightGrayColor];
}
#pragma mark -
#pragma mark Setter/Getters
- (void) setPlaceholder:(NSString *)aPlaceholder {
if ([self.realTextisEqualToString:placeholder] && ![selfisFirstResponder]) {
self.text = aPlaceholder;
}
if (aPlaceholder != placeholder) {
placeholder = aPlaceholder;
}
[selfendEditing:nil];
}
- (void)setPlaceholderColor:(UIColor *)aPlaceholderColor {
placeholderColor = aPlaceholderColor;
if ([super.textisEqualToString:self.placeholder]) {
self.textColor =self.placeholderColor;
}
}
- (NSString *) text {
NSString* text = [supertext];
if ([text isEqualToString:self.placeholder])return @"";
return text;
}
- (void) setText:(NSString *)text {
if (([text isEqualToString:@""] || text ==nil) && ![selfisFirstResponder]) {
super.text =self.placeholder;
}
else {
super.text = text;
}
if ([text isEqualToString:self.placeholder] || text ==nil) {
self.textColor =self.placeholderColor;
}
else {
self.textColor =self.realTextColor;
}
}
- (NSString *) realText {
return [supertext];
}
- (void) beginEditing:(NSNotification*) notification {
if ([self.realTextisEqualToString:self.placeholder]) {
super.text =nil;
self.textColor =self.realTextColor;
}
}
- (void) endEditing:(NSNotification*) notification {
if ([self.realTextisEqualToString:@""] ||self.realText ==nil) {
super.text =self.placeholder;
self.textColor =self.placeholderColor;
}
}
- (void) setTextColor:(UIColor *)textColor {
if ([self.realTextisEqualToString:self.placeholder]) {
if ([textColor isEqual:self.placeholderColor]){
[supersetTextColor:textColor];
}else {
self.realTextColor = textColor;
}
}
else {
self.realTextColor = textColor;
[supersetTextColor:textColor];
}
}
#pragma mark -
#pragma mark Dealloc
- (void)dealloc {
[[NSNotificationCenterdefaultCenter] removeObserver:self];
}
@end
- iOS 客户端学习-UITextView
- ios学习--UItextview
- ios学习笔记-Lecture5:UITextView
- iOS学习之----------自定义UITextView
- iOS之UI学习-UITextView
- UITextView 控件-IOS开发
- UITextView 控件-IOS开发
- Swift开发IOS-UITextView
- iOS学习--UITextView的那些事
- IOS学习之——UITextView
- iOS客户端学习-MJRefresh
- ios客户端学习-UIButton
- iOS客户端学习-校验
- ios客户端学习-AFNetWoriking
- ios客户端学习-bitcode
- iOS客户端学习-SDWebImage
- ios客户端学习-github
- ios客户端学习-EGOCache
- String类常见的方法
- Quartz插件的使用
- 发送邮件
- (javaweb读书笔记系列之二)servletconfig和servletcontext
- 判断文件的编码方式
- iOS 客户端学习-UITextView
- js 字符串转化成数字
- 水波效果
- Fragment+TabHost模仿新浪新闻布局界面
- My97DatePicker时间控件使用
- 一些冷门却有用的小知识
- JQuery上传插件Uploadify使用详解
- 1017. A除以B (20)
- 基于vitamio的网络电视直播源码