简介
我们使用UITextView时,偶会有需要类似UITextField的placeholer的占位符功能, 这里实现了支持placeholder的UITextView, 并且简化设置TextView内边距功能。
代码示例
KKPlaceholderTextView *testTF = [[KKPlaceholderTextView alloc] initWithFrame:CGRectMake(50, 100, 100, 50)];
testTF.placeholder = @"请输入描述内容";
NSDictionary * attributesDic = @{ NSFontAttributeName:[UIFont boldSystemFontOfSize:12],
NSForegroundColorAttributeName:[UIColor redColor]
};
testTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入描述内容" attributes:attributesDic];
// 设置textView 内边距
testTF.padding = UIEdgeInsetsMake(10, 10, 10, 10);
[self.view addSubview:testTF];
Cocoapods
pod 'KKPlaceholderTextView'
网友评论