转载: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. KingbaseES V8R3集群维护案例之---pcp_node_refresh应用

    案例说明: 在一次KingbaseES V8R3集群切换分析中,运维人员执行了pcp_node_refresh,导致集群发生了failover的切换.此文档对pcp_node_refresh工具做了应 ...

  2. [转并修改]C#编程中跨线程访问控件

    C#编程中跨线程访问控件 一.简述 二.Winforms中跨线程访问控件 三.WPF中跨线程访问控件 参考文档 一.简述 C#中不允许跨线程直接访问界面控件,即一个线程中如主线程创建的控件不允许被其他 ...

  3. 2022-11-19学习内容-Server端代码编写-Client端代码编写

    1.Server端代码编写 1.1UserDBHelper.java package com.example.chapter07_server.database; import android.con ...

  4. APP学习4

    1.Toast Toast是Android系统提供的轻量级信息提醒制度,用于向用户提示即时信息,它显示在引用程序界面的最上层,显示一段时间后自动消失,不会打断当前操作,也不获得焦点. Toast.ma ...

  5. 一些开源软件的LOGO

    整理一些开源软件的logo或者吉祥物,主要是一些以动物形象为主的logo. 1. GNU,不是一个软件,而是一个软件组织,包括很多知名的软件例如GCC编译器. GNU的LOGO是一只牛. GCC的lo ...

  6. jar打包exe选型

    网上一搜有篇文章写了9中不同工具方法,最后使用launch4j,其实就一点开源免费. launch4j>bsd3协议(可免费商用),像exe4j需要license. 经过摸索终于搞定一键启动并且 ...

  7. 动态规划-3-RNA的二级结构

    /*状态转移方程: OPT(i , j)= max(OPT(i , j − 1) , max( 1+OPT(i , t − 1)+OPT(t + 1, j − 1))), where the  max ...

  8. sdp安装及实例

    环境: sdpserver:192.168.1.160 sdpclient:192.168.1.161 安装 yum install gcc gcc-c++ libpcap* libtool* wge ...

  9. Linux firewall 命令

    常用命令 开启端口命令 firewall-cmd --zone=public--add-port=443/tcp --permanent --zone  #作用域 --add-port=80/tcp ...

  10. 关于sql时间方面的处理

    查询大于时间两小时(例:订单设置两小时后过期 $res = Order::where(['status'=>0,'sid'=>1])->whereRaw("created_ ...