转载: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的更多相关文章

  1. ios 设置UITextField的placeholder大小颜色

    需求:产品嫌弃placeholder的字体太大,颜色太明显,要求跟正常输入时的字体及颜色不同 方法:设置placeholder的大小和颜色,实际上是设置placeholder的label的大小和颜色, ...

  2. iOS 设置TextView控件内容行间距

    - (BOOL)textViewShouldBeginEditing:(UITextView *)textView { if (textView.text.length < 1) { textV ...

  3. iOS 设置UITextView的Placeholder

    代码如下: - (void)setupTextView { UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, ...

  4. iOS开发之UITextView,设置textView的行间距及placeholder

    一.设置textView的行间距 1.如果只是静态显示textView的内容为设置的行间距,执行如下代码: //    textview 改变字体的行间距     NSMutableParagraph ...

  5. 李洪强iOS开发之带placeHolder的Textview

    李洪强iOS开发之带placeHolder的Textview  01 - 创建工过程,定义全局属性,遵守textview的代理协议  02 - 添加一个textview和一个label 03 - 实现 ...

  6. 如何设置TextView控件的背景透明度和字体透明度

    如何设置TextView控件的背景透明度和字体透明度 设计师给的标注都是类似这样的: 字号:26 颜色:#000000 透明度:80% 其实,程序上只要需要一个色值就OK了,那么这个色值我如何计算呢? ...

  7. Android中设置TextView的颜色setTextColor

    tv.setTextColor(Color.parseColor("#FFFFFF")); tv.setTextColor(Color.WHITE); tv.setTextColo ...

  8. css设置input中placeholder字体

    设置input中placeholder字体颜色 input::-webkit-input-placeholder {color:@a;} input:-moz-placeholder {color:@ ...

  9. iOS设置app应用程序文件共享

    1.iOSapp应用程序文件共享 当我们用itnues连接到设备时,在应用程序栏目下面,文件共享下,点击 对应的程序,即可以在程序右边栏目里面看到应用程序共享的数据, 此时,我们可以通过右下角的 添加 ...

  10. IOS 设置定时器

    IOS 设置定时器  自动滚动视图 定时发送坐标信息 即时显示 时钟 NSTimer *timer; - (void)start {//1second 调用一次 timer = [NSTimer sc ...

随机推荐

  1. Generative Adversarial Network - Python实现

    算法特征 ①. discriminator区别真假; ②. generator以假乱真 算法推导 Part Ⅰ: 熵之相关定义 entropy之定义如下, \[\begin{equation*} H( ...

  2. Docker CLI docker buildx bake 常用命令

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中,然后发布到任何流行的 Linux或Windows操作系统的机器上,也可以实现虚拟化.Docker是内核 ...

  3. C#如何判断文件是否存在

    https://jingyan.baidu.com/article/ac6a9a5ead6ef86b653eac8b.html 首先,我们定义一个字符串,名为path. 然后,我们给他一个路径,这样才 ...

  4. python 嵌套对象转为dict

    as_dict(self, keys=None, exclude_keys=None): """ 将ORM对象序列化为字典 :param keys: :return: & ...

  5. Mybatis缓存(3)

    10.4.3二级缓存

  6. P5737 闰年展示

    快乐的题目穿梭机 这道题目其实so easy啦,还是先来顺一遍流程: 输入数据 列举出x到y区间内的年份 判断是否是闰年 是闰年cnt(或sum)计数器++ 输出计数器和年份 闰年知识补充站 1.能被 ...

  7. pytest学习总结

    官方pytest文档:Full pytest documentation - pytest documentation 一.pytest以及辅助插件的安装 1.pytest安装 pip install ...

  8. py07-文件处理

    """什么是文件? 操作系统提供给用户操作复杂硬件(硬盘)的简易的接口 为什么操作文件 人或者应用程序需要永久的保存数据 如何用 f = open() f.read() ...

  9. MySQL 的limit

    题目 limit:从倒数第二行开始,往前查找一行

  10. bash脚本的判断语句之一

    开始学习bash的"编程"操作. 其实严格来说,这个脚本语言的语法是比较古老和特殊的,有很多不符合中国人习惯的东西. 因为在中国人的世界里,电脑键盘上面的使用shift才能输出来的 ...