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 ...
随机推荐
- solve--ifconifg命令提示没有该命令解决方法
一.如果你/bin目录下有ifconfig,则是命令路径没有在环境变量中添加,很多新装的linux系统都会存在这种问题 打开/etc/profile文件 命令: vi /et ...
- GitHub创建仓库导入项目
1.进入主页,点击+号 2.填写仓库名称 3.记住网址! 4.项目所在文件夹路径 5.打开Git Bash 6.输入命令 $ cd C: $ cd AndroidTasks $ cd MusicPla ...
- 可收集ALC问题[Microsoft.Data.SqlClient is not supported on this platform.]
异常 Microsoft.Data.SqlClient is not supported on this platform. 堆栈跟踪 at Microsoft.Data.SqlClient.SqlC ...
- kubernetes:v1.25 + containerd
由于kubernets从v1.24开始停止支持dockershim,kubernets不再支持通过docker来创建和管理容器.本文记录安装kubernetes v1.25 + containerd ...
- ESXI密码正确无法登录
场景描述: 今天新安装了一个VMware ESXi 6.5的系统,密码仍然用的习惯采用的密码.但在使用中,无论是使用vSphere Client连接,还是在vCenter Server中添加这台ESX ...
- SQL执行定时任务JOB,包教包会
什么是JOB? 数据库中可以定时执行任务的功能组件,那就是JOB. JOB的作用 它可以按我们设置好的参数定时执行查询语句或存储过程,特别适合一些每天,每周,每月,每年这种需要循环执行任务的场景,当然 ...
- Tensorflow框架实现中的“三”种图
https://zhuanlan.zhihu.com/p/31308381 图(graph)是 tensorflow 用于表达计算任务的一个核心概念.从前端(python)描述神经网络的结构,到后端在 ...
- MSSQL Always Encrypted 加密
载自:https://zhuanlan.zhihu.com/p/63674006 文档资源:https://docs.microsoft.com/zh-CN/sql/relational-databa ...
- 初玩mybatis-Plus踩过的小坑(粗心大意)
一开始没设置全局id为数据库自增长(数据库也要勾上自增长) 他是默认使用ID_WORKER生成id的 ,然后当我重新设置为自增长后 发现生成的id还是20位数,局部id也设置了 还是没用 ,百度说哪个 ...
- node-sass低版本与高版本的node会有兼容性问题,导致安装失败
node版本v14.18.1 node-sass版本v4.13.0 Python 2.7.18