转载: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. 2023-03-01 'react-native' 不是内部或外部命令,也不是可运行的程序 这个报错是因为你没有全局安装react-native的脚手架,请执行下面代码全局安装react-native脚手架👇

    问题描述:想要初始化一个新的rn项目,执行[react-native init myApp --version 0.68.2],报错:'react-natvie' 不是内部或外部命令,也不是可运行的程 ...

  2. kafka 常见命令以及增加topic的分区数

    基础命令 1.创建topic kafka-topics.sh --bootstrap-server ${kafkaAddress} --create --topic ${topicName} --pa ...

  3. 阿里云仓库构建gcr镜像

    经常用到gcr的镜像,但是由于国内无法访问,使用阿里云仓库构建 例如需要获取:gcr.io/spiffe-io/spire-server:1.0.1 镜像 1.使用阿里云code,创建项目,新项目 增 ...

  4. ElasticSearch入门学习笔记

    ElasticSearch入门笔记 分页查询 from: 开始位置 size: 查多少条 GET /credit_enterprise_info/_search { "query" ...

  5. C++ 11 数字转字符串新功能

    // 头文件 <string>string to_string (int val);string to_string (long val);string to_string (long l ...

  6. Oracle JDK 和 OpenJDK 有什么区别?

    OpenJDK是Sun在2006年末把Java开源而形成的项目,这里的"开源"是通常意义上的源码开放形式,即源码是可被复用的,例如IcedTea.UltraViolet都是从Ope ...

  7. 巴恩斯利蕨 The Barnsley Fern

    巴恩斯利蕨学习链接 下面用R画一下: npts<-50000 point_mat<-matrix(data=NA,nrow=npts,ncol=2) list_fun<-list( ...

  8. nginx配置根据url的参数值进行转发

    server { listen 8081; location / { set $tag ""; set $cs "/index/test/test"; prox ...

  9. mysql 创建表 datetime NOT NULL DEFAULT '0000-00-00 00:00:00' 默认值失败

    set global sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREAT ...

  10. DDD(二)聚合、聚合根、领域服务、应用服务、仓储”和“工作单元”、领域事件、集成事件

    DDD(二)聚合.聚合根.领域服务.应用服务.仓储"和"工作单元".领域事件.集成事件 如果觉得样式不好:跳转即可 http://www.lifengying.site/ ...