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 ...
随机推荐
- kafka 常见命令以及增加topic的分区数
基础命令 1.创建topic kafka-topics.sh --bootstrap-server ${kafkaAddress} --create --topic ${topicName} --pa ...
- insert_base_x.txt
insert into g_temp.test_basevalues('20220202'::date, 1, 'apple'),('20220203'::date, 5, 'banana'),('2 ...
- 开启Runjar , 使用beeline连接hive
要先开启hadoop服务 进入root用户hive目录 输入bin/hiveservices.sh stop 停止 输入bin/hiveservices.sh start ...
- js获取父节点的方式
js获取父节点的方式: 1.parentNode获取父节点 获取的是当前元素的直接父元素.parentNode是w3c的标准. var p = document.getElementById(&quo ...
- Vue2 element-ui组件二封-表单组件-效果展示
vue2已经落后了? 不着急, vue3的也在写的过程中, 只是发出来vue2的一些组件 系列说明: > 编写原因 vue2在很多人眼里已经快过时了, 而我一直想写一些总结, 但是从两年前到现在 ...
- eclipse配置tomcat环境
Eclipse配置tomcat环境 第一步:进行下面操作: window–>Preference–>Server–>Runtime Environments ->Add 搜索s ...
- 【运维】通过gotty实现网页代理访问服务器及K8S容器操作实践
Gotty 是Golang编写的可以方便的共享系统终端为web应用,是一个灵活强大的通过web访问终端的工具.本文将主要通过搭建Gotty实现对K8S容器的访问操作,开发如果想要正常的进行容器访问以及 ...
- mac Big Sur 打开应用提示,您没有权限来打开应用程序
终端输入codesign --force --deep --sign - /Applications/{AppName.app}注意{AppName.app} 替换为无法打开的应用程序名,将尝试强制签 ...
- NVIDIA的GPU算力Compute Capalibity
可查看官方查询地址:https://developer.nvidia.com/cuda-gpus
- MVC页面加载速度优化小记
前言: 最近做一个地图展示页面,业务初期没什么问题,运行一阵后报错: Error during serialization or deserialization using the JSON Jav ...