iOS设置textView的placeholder
转载:http://blog.sina.com.cn/s/blog_7a1b23430102wkys.html
#import "ViewController.h"
@interface ViewController ()<</span>UITextViewDelegate>
{
UILabel *textViewPlaceholderLabel;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
1、在UITextView上加上一个UILabel
textViewPlaceholderLabel = [[UILabel alloc] initWithFrame:CGRectMake(53, 202, 150, 25)];
textViewPlaceholderLabel.text = @"请输入你的内容";
textViewPlaceholderLabel.textColor = [UIColor grayColor];
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(50, 200, 150, 250)];
textView.delegate = self;
textView.backgroundColor = [UIColor clearColor];
textView.layer.borderWidth = 1.0f;
textView.layer.borderColor = [UIColor blackColor].CGColor;
[self.view addSubview: textViewPlaceholderLabel];
[self.view addSubview: textView];
}
//设置textView的placeholder
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
//[text isEqualToString:@""] 表示输入的是退格键
if (![text isEqualToString:@""])
{
textViewPlaceholderLabel.hidden = YES;
}
//range.location == 0 && range.length == 1 表示输入的是第一个字符
if ([text isEqualToString:@""] && range.location == 0 && range.length == 1)
{
textViewPlaceholderLabel.hidden = NO;
}
return YES;
}
iOS设置textView的placeholder的更多相关文章
- ios 设置UITextField的placeholder大小颜色
需求:产品嫌弃placeholder的字体太大,颜色太明显,要求跟正常输入时的字体及颜色不同 方法:设置placeholder的大小和颜色,实际上是设置placeholder的label的大小和颜色, ...
- iOS 设置TextView控件内容行间距
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView { if (textView.text.length < 1) { textV ...
- iOS 设置UITextView的Placeholder
代码如下: - (void)setupTextView { UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, ...
- iOS开发之UITextView,设置textView的行间距及placeholder
一.设置textView的行间距 1.如果只是静态显示textView的内容为设置的行间距,执行如下代码: // textview 改变字体的行间距 NSMutableParagraph ...
- 李洪强iOS开发之带placeHolder的Textview
李洪强iOS开发之带placeHolder的Textview 01 - 创建工过程,定义全局属性,遵守textview的代理协议 02 - 添加一个textview和一个label 03 - 实现 ...
- 如何设置TextView控件的背景透明度和字体透明度
如何设置TextView控件的背景透明度和字体透明度 设计师给的标注都是类似这样的: 字号:26 颜色:#000000 透明度:80% 其实,程序上只要需要一个色值就OK了,那么这个色值我如何计算呢? ...
- Android中设置TextView的颜色setTextColor
tv.setTextColor(Color.parseColor("#FFFFFF")); tv.setTextColor(Color.WHITE); tv.setTextColo ...
- css设置input中placeholder字体
设置input中placeholder字体颜色 input::-webkit-input-placeholder {color:@a;} input:-moz-placeholder {color:@ ...
- iOS设置app应用程序文件共享
1.iOSapp应用程序文件共享 当我们用itnues连接到设备时,在应用程序栏目下面,文件共享下,点击 对应的程序,即可以在程序右边栏目里面看到应用程序共享的数据, 此时,我们可以通过右下角的 添加 ...
- IOS 设置定时器
IOS 设置定时器 自动滚动视图 定时发送坐标信息 即时显示 时钟 NSTimer *timer; - (void)start {//1second 调用一次 timer = [NSTimer sc ...
随机推荐
- springmvc的Interceptor拦截器和servlet的filter过滤器
springmvc的Interceptor拦截器和servlet的filter过滤器 1.springmvc的Interceptor拦截器和servlet的filter过滤器springboot实现方 ...
- DP7361 是一款立体声六通道线性输出的数模转换器-兼容CS4361
DP7361 是一款立体声六通道线性输出的数模转换器,内含插值滤波器.Multi-Bit 数模转换器.模拟输出滤波器,支持主流的音频数据格式. DP7361 片上集成线性低通模拟滤波器和四阶Multi ...
- npm vue-router安装报错
因为2022年2月7日以后,vue-router的默认版本,为4版本,而且 vue-router4,只能在vue3中,只有vue-router3中,能用在vue 2中 如果把vue-router4强制 ...
- HANA 2022 ME21N \ME31K 客制字段
问题:客制字段维护不上去 解决方案:抬头字段 打补丁 note 3275982 - Data loss observed in custom fields when working in the tr ...
- php不缓存直接输出
ini_set('max_execution_time', 600); header('X-Accel-Buffering:no'); ob_end_flush(); $l_zhen = \M('zh ...
- debug / support 的步骤 / 解决问题的步骤
尽量避免去看代码, 而是去作为当前用户去测试各种场景, 肯定有的场景是有问题的, 有点场景是没有问题, 那有问题和没有问题之间, 就能知道为什么了.代码太纷繁芜杂了, 看不懂的, 出问题都是在某个或者 ...
- (K8s学习笔记六)Pod的调度
RC(ReplicationController)只能选择一个标签,RS(ReplicaSet)可选择多个标签,例如APPTest发布了v1和v2两个版本,并希望副本数为3,可同时包含v1和v2两个版 ...
- php8.0.0新功能:Match表达式
Match表达式是基于值的一致性进行分支计算.它的比较是严格比较.Match表达式从php8.0.0起可用.示例代码: 1 $key = 'key_1'; 2 $value = match($key) ...
- HDMI基础知识
小插曲: HDMI代表TV阵营(2002年发布,抢占市场先机) DP1.2/1.4/2.0代表电脑阵营(2006年发布,电脑厂家不想受制于TV) 由来: HDMI(High-Definition Mu ...
- VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory.
macOS VirtualBox Bridged Adapter 不能用 I'm running macOS High Sierra 10.13.1 and VirtualBox 5.2.2. Thi ...