自定义textView的placeholder和边框
想实现的效果:



//
// LHQsuggestionViewCtrl.m
// A13 - 设置
//
// Created by vic fan on 16/6/23.
// Copyright © 2016年 李洪强. All rights reserved.
//
#import "LHQsuggestionViewCtrl.h"
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
@interface LHQsuggestionViewCtrl ()<UITextViewDelegate>
@property(nonatomic,strong)UILabel *label1;
@property(nonatomic,weak)UITextView *textView1;
@end
@implementation LHQsuggestionViewCtrl
- (void)viewDidLoad{
[super viewDidLoad];
self.title = @"意见反馈";
// self.view.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1];
self.view.backgroundColor = [UIColor whiteColor];
//----------------------设置带place
UITextView *textView = [[UITextView alloc] init];
self.textView1 = textView;
self.textView1.font = [UIFont systemFontOfSize:14];
self.textView1.frame =CGRectMake(20, 150,[UIScreen mainScreen].bounds.size.width -40, 200);
self.textView1.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.textView1.layer.borderColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1].CGColor;
self.textView1.layer.masksToBounds = YES;
self.textView1.layer.borderWidth = 1;
self.textView1.backgroundColor = [UIColor whiteColor];
// self.modalPresentationCapturesStatusBarAppearance = NO;
// self.edgesForExtendedLayout = UIRectEdgeNone;
// self.extendedLayoutIncludesOpaqueBars = NO;
[self.view addSubview:self.textView1];
self.textView1.hidden = NO;
self.textView1.delegate = self;
self.automaticallyAdjustsScrollViewInsets =NO;
//其次在UITextView上面覆盖个UILable,UILable设置为全局变量。
UILabel *label1 = [[UILabel alloc]init];
self.label1 = label1;
self.label1.frame =CGRectMake(3, 3, [UIScreen mainScreen].bounds.size.width -50, 20);
self.label1.text = @"请输入您的宝贵意见,建议,我们将不断完善";
self.label1.enabled = NO;//lable必须设置为不可用
self.label1.backgroundColor = [UIColor clearColor];
self.label1.font = [UIFont systemFontOfSize:14];
[self.textView1 addSubview:self.label1];
//----------------------------------------------------------
UILabel *topLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 80, 150, 30)];
topLabel.text = @"您的宝贵建议:";
[self.view addSubview:topLabel];
}
// 实现UITextView的代理
-(void)textViewDidChange:(UITextView *)textView
{
self.textView1.text = textView.text;
if (textView.text.length == 0) {
self.label1.text = @"请输入您的宝贵意见,建议,我们将不断完善";
}else{
self.label1.text = @"";
}
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
self.label1.text = @"";
// [self.label1 removeFromSuperview];
return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
self.label1.text = @"请输入您的宝贵意见,建议,我们将不断完善";
return YES;
}
- (void)btnClick{
NSLog(@"点击了提示");
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[UIView animateWithDuration:0.8 animations:^{
[self.view endEditing:YES];
}];
}
@end
自定义textView的placeholder和边框的更多相关文章
- ios开发之自定义textView
自定义textView,从理论上讲很简单,根据需求自定义,比如我在开发中的需求就是现实一个字数的限制以及根据输入的文字改变提示剩余字数,那么开始我的基本思路就是自定义一个View,而里面包含一个子控件 ...
- 自定义TextView 调用ttf格式字体
自定义TextView 调用ttf格式字体 1.<strong>将ttf格式文件存放在assets/fonts/下</strong> 注:PC系统字体存放在C:\Windows ...
- [原创]Android秒杀倒计时自定义TextView
自定义TextView控件TimeTextView代码: import android.content.Context; import android.content.res.TypedArray; ...
- 安卓自定义TextView实现自动滚动
xml文件代码 <com.mobile.APITest.ScrollEditText android:id="@+id/statusEditText" android:lay ...
- Android开发学习笔记-自定义TextView属性模版
如果项目中有很多个控件使用的是同一种样式,则为了方便,可以将样式设置到系统中去,这样使用的时候会方便很多. 下面是自定义样式模版的方法. 1.在style.xml文件中添加自己要设置的样式内容 < ...
- 自定义TextView带有各类.ttf字体的TextView
最近项目遇到了将普通文字转化为带有字体样式的文字,这里就涉及到了.ttf文件,我上网百度了不少资料最终终于实现了,现在想想其实并不复杂 1,你需要下载一种.ttf字体文件,你可以从网上找到一种字体的. ...
- Android源码分析(十二)-----Android源码中如何自定义TextView实现滚动效果
一:如何自定义TextView实现滚动效果 继承TextView基类 重写构造方法 修改isFocused()方法,获取焦点. /* * Copyright (C) 2015 The Android ...
- 练习,自定义TextView(1.1)
重新自定义TextView是非常有趣的事情,跟着Android4高级编程,通过自定义TextView,来敲一下代码: 这个是那么的简单,自定义TextView,新建CustomTextView继承Te ...
- 自定义textview
#import <UIKit/UIKit.h> @class FSTextView; typedef void(^FSTextViewHandler)(FSTextView *textVi ...
随机推荐
- LookupError: unknown encoding: cp65001
在CMD下解释运行python时出现LookupError: unknown encoding: cp65001错误(编码错误) 在cmd下chcp命令(大概是change codepage?)可查看 ...
- 如何使用SQLMAP绕过WAF
WAF(web应用防火墙)逐渐成为安全解决方案的标配之一.正因为有了它,许多公司甚至已经不在意web应用的漏洞.遗憾的是,并不是所有的waf都是不可绕过的!本文将向大家讲述,如何使用注入神器SQLMa ...
- Walle代码发布系统
Walle 一个web部署系统工具,配置简单.功能完善.界面流畅.开箱即用!支持git.svn版本管理,支持各种web代码发布,PHP,Python,JAVA等代码的发布.回滚,可以通过web来一键完 ...
- 在执行migrate的时候出现问题(错误见末尾): django.db.utils.OperationalError: (1045, "Access denied for user ‘ODBC‘@‘localho st‘ (using password: YES)")
Python框架之Django的数据库 在执行migrate的时候出现问题(错误见末尾) django.db.utils.OperationalError: (1045, "Access d ...
- vc6下unicode支持
最近在研究一个串口程序,要启用unicode支持,发现还挺麻烦的. VC6.0设定UNICODE编译环境 VC++ 6.0支持Unicode编程,但默认的是ANSI,所以开发人员只需要稍微改变一下编写 ...
- .NET Framwork 之 托管代码的执行过程
源代码代码第一次编译形成IL中间语言的托管代码,在运行时被Class Loader装载后进行JIT第二次编译形成托管的本地代码.在执行过程中,它会不断地检查当前我们执行的代码的安全性和规范性. Cla ...
- Django 学习记录
这是我自己理解并自己画的,django 请求示意图,表示了它的组织方式. project manage.py: 主要工具文件 settings.py: 配置文件 urls.py: url 定义及其指向 ...
- Tomcat的server.xml配置讲解(一)
一.Tomcat虚拟目录的配置 1.服务器配置 默认端口号为8080,如果要想修改端口号,则可以在Tomcat目录中的conf/server.xml文件,找到如下代码,将端口号改为:80:保存serv ...
- java检索文件时加入线程
package xianChengSaomiao; import java.io.File; import java.util.ArrayList; import java.util.List; pu ...
- [读后感]spring Mvc 教程框架实例以及系统演示下载
[读后感]spring Mvc 教程框架实例以及系统演示下载 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致&qu ...