美文网首页iOS开发知识小集
iOS UITextView 实现placeholder占位符功

iOS UITextView 实现placeholder占位符功

作者: 小可无敌斩 | 来源:发表于2019-03-08 18:06 被阅读0次

简介


我们使用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'

相关链接


Github: [https://github.com/cocoZ/KKPlaceholderTextView]

相关文章

网友评论

    本文标题:iOS UITextView 实现placeholder占位符功

    本文链接:https://www.haomeiwen.com/subject/bhkdpqtx.html