用UITextView模拟UITextField的placeHolder
用UITextView模拟UITextField的placeHolder
效果:
源码:
//
// ViewController.m
// TextView
//
// Created by YouXianMing on 14/12/18.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "ViewController.h" static NSString *placeHolderStr = @"User Name"; @interface ViewController ()<UITextViewDelegate> @property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UIButton *button; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 反应的按钮
self.button = [[UIButton alloc] initWithFrame:self.view.bounds];
[self.button addTarget:self
action:@selector(buttonEvent)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.button]; // textView
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(, , , )];
self.textView.layer.borderWidth = .f;
self.textView.layer.borderColor = [UIColor grayColor].CGColor;
self.textView.delegate = self;
self.textView.text = placeHolderStr;
self.textView.font = [UIFont systemFontOfSize:.f];
self.textView.textColor = [UIColor grayColor];
[self.view addSubview:self.textView];
} #pragma mark - 代理方法
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
// 设置编辑状态文字颜色
textView.textColor = [UIColor blackColor]; // 如果文字为placeHolder文字
if ([textView.text isEqualToString:placeHolderStr]) {
textView.text = @"";
} return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView { // 如果长度为0,则显示placeHolder文字
if (textView.text.length == ) {
textView.text = placeHolderStr;
textView.textColor = [UIColor grayColor];
} return YES;
} /**
* 反应的按钮
*/
- (void)buttonEvent {
[self.textView resignFirstResponder];
} @end
核心代码:
用UITextView模拟UITextField的placeHolder的更多相关文章
- UITextView模拟UITextField 设置Placeholder属性 --董鑫
由于最近有用到输入框,刚开始考虑的是UITextField,因为它在没有输入的时候可以有提示的Placeholder更能,很人性化,但UITextField只能单行输入,不能跳行,对于一些强迫症的亲来 ...
- UITextView和UITextField的placeholder,键盘隐藏,键盘换行变完成字样
本文转载至 http://blog.csdn.net/hengshujiyi/article/details/9086093- (void)initFeedBackViews { //设置页面的背景颜 ...
- [BS-19]更改UITextField的placeholder文字颜色的5种方法
更改UITextField的placeholder文字颜色的5种方法 想要达到的目标是:一个页面上有多个UITextField,当用户聚焦某textField时,该文本框的placeholder的文字 ...
- 修改UITextfield的Placeholder字体的颜色
- (void)viewDidLoad { [super viewDidLoad]; self.title=@"修改UITextField的placeholder字体颜色"; UI ...
- UITextView与UITextfield的区别
IOS中的UITextView和UITextField都是文本输入控件并都能够调用系统键盘.本次特酷把介绍UITextView和UITextField的区别.简单来说,UITextView和UITex ...
- iOS UITextField设置placeholder颜色
设置UITextField的placeholder颜色 UIColor *color = [UIColor blackColor]; textField.attributedPlaceholder = ...
- 【修改 UITextField 中 placeholder 的顏色】
第一种方法: [textfeild setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"]; ...
- UITextfield设置Placeholder颜色 控件 内边距、自适应高度
//创建UITextField对象 UITextField * tf=[[UITextField alloc]init]; //设置Placeholder颜色 [text setAttribut ...
- iOS-改变UITextField的Placeholder颜色的三种方式
转自:http://blog.csdn.net/mazy_ma/article/details/51775670 有时,UITextField自带的Placeholder的颜色太浅或者不满足需求,所以 ...
随机推荐
- 用sinopia搭建内部npm服务
sinopia搭建 这里默认你已经有node环境了,执行下面命令,全局安装 sinopia npm install -g sinopia 安装好后,执行下面命令启动 sinopia sinopia 你 ...
- mysql 导出数据到csv文件的命令
1.导出本地数据库数据到本地文件 mysql -A service_db -h your_host -utest -ptest mysql> select * from t_apps where ...
- C#正则表达式合并连续空格为单个空格
第一种方法: 使用 System.Text.RegularExpressions.Regex.Replace()方法 string result = String.Empty; string str ...
- SharePoint 2013创建应用程序时IIS端口文件夹下没文件
最近SharePoint 2007迁移到2013的时候,碰到创建应用程序时IIS端口文件夹下没文件的问题,网上找了大把的原因,终于在这里找到了解决方案: Fix: 1. Open IIS on the ...
- Mybatis中同时使用shardbatis和pagehelper插件冲突问题
在一次使用mybatis的插件,分表shardbatis+分页pagehelper共同使用的时候,会抛出以下异常: java.lang.NoSuchMethodError: net.sf.jsqlpa ...
- CUBA 7 新特性 (下篇)
上篇我们主要介绍了 CUBA 7 中前端的一些主要功能.这篇我们介绍一下中间件的一变化和新特性. 中间件功能 前面关于新的界面 API 的描述内容比我预期的要多许多,所以在这一节,我会尽量简单点说! ...
- .NET环境下使用水晶报表
.NET环境下使用水晶报表 听语音 | 浏览:3280 | 更新:2013-12-20 13:36 1 2 3 4 5 6 7 分步阅读 水晶报表(Crystal Reports)-商务智能软件,通常 ...
- Sql-Server触发器,根据条件匹配另一个表中的字段
USE [CDM] GO /****** Object: Trigger [dbo].[UpdateAkisFlight] Script Date: 2018/6/14 16:43:29 ****** ...
- dubbo基于tcp协议的RPC框架
什么是 RPC 框架 谁能用通俗的语言解释一下什么是 RPC 框架? - 远程过程调用协议RPC(Remote Procedure Call Protocol) 首先了解什么叫RPC,为什么要RPC, ...
- vue+element ui 的时间控件选择 年月日时分
前言:工作中用到 vue+element ui 的前端框架,需要选择年月日时分,但element ui官网demo有没有,所以记录一下.转载请注明出处:https://www.cnblogs.com/ ...