定制textField

版权声明:本CSDN博客所有文章不会即时更新,请关注个人博客:http://www.huangyibiao.com/
- //
- // HYBTextField.h
- // CloudShopping
- //
- // Created by sixiaobo on 14-7-10.
- // Copyright (c) 2014年 com.Uni2uni. All rights reserved.
- //
- #import <UIKit/UIKit.h>
- /*!
- * @brief 自定义TextField,用于修改默认textfield的属性为我们工程中需要的属性
- * @author huangyibiao
- */
- @interface HYBTextField : UITextField
- @property (nonatomic, strong) UIColor *placeholderColor;
- @property (nonatomic, strong) UIFont *placeholderFont;
- @property (nonatomic, assign) CGFloat leftPadding;
- // 默认leftPadding = 8.0
- - (id)initWithFrame:(CGRect)frame placeholderColor:(UIColor *)color font:(UIFont *)font;
- - (id)initWithFrame:(CGRect)frame placeholderColor:(UIColor *)color font:(UIFont *)font leftPadding:(CGFloat)leftPadding;
- @end
- //
- // HYBTextField.m
- // CloudShopping
- //
- // Created by sixiaobo on 14-7-10.
- // Copyright (c) 2014年 com.Uni2uni. All rights reserved.
- //
- #import "HYBTextField.h"
- @implementation HYBTextField
- - (id)initWithFrame:(CGRect)frame placeholderColor:(UIColor *)color font:(UIFont *)font {
- return [self initWithFrame:frame placeholderColor:color font:font leftPadding:8];
- }
- - (id)initWithFrame:(CGRect)frame
- placeholderColor:(UIColor *)color
- font:(UIFont *)font
- leftPadding:(CGFloat)leftPadding {
- if (self = [super initWithFrame:frame]) {
- self.placeholderColor = color;
- self.placeholderFont = font;
- self.leftPadding = leftPadding;
- self.autocapitalizationType = UITextAutocapitalizationTypeNone;
- self.autocorrectionType = UITextAutocorrectionTypeNo;
- self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- self.borderStyle = UITextBorderStyleNone;
- self.backgroundColor = [UIColor whiteColor];
- }
- return self;
- }
- - (void)drawPlaceholderInRect:(CGRect)rect {
- [kColorWith16RGB(0xa8a8a8) setFill];
- [[self placeholder] drawInRect:CGRectMake(self.leftPadding, rect.origin.y, rect.size.width, rect.size.height)
- withFont:self.placeholderFont];
- return;
- }
- // 控制编辑文本的位置
- - (CGRect)editingRectForBounds:(CGRect)bounds {
- CGFloat padding = self.leftPadding;
- if (self.textAlignment == NSTextAlignmentRight) {
- padding = 0;
- }
- CGRect inset = CGRectMake(bounds.origin.x + padding, bounds.origin.y,
- bounds.size.width, bounds.size.height);
- return inset;
- }
- - (CGRect)placeholderRectForBounds:(CGRect)bounds {
- NSString *obtainSizeString = self.text;
- CGSize size = [obtainSizeString sizeWithFont:self.placeholderFont];
- return CGRectMake(bounds.origin.x, (bounds.size.height - size.height) / 2,
- bounds.size.width, bounds.size.height);
- }
- // 控制显示文本的位置
- - (CGRect)textRectForBounds:(CGRect)bounds {
- CGFloat padding = self.leftPadding;
- if (self.textAlignment == NSTextAlignmentRight) {
- padding = 0;
- }
- CGRect inset = CGRectMake(bounds.origin.x + padding, bounds.origin.y,
- bounds.size.width, bounds.size.height);
- return inset;
- }
- @end
定制textField的更多相关文章
- iOS TextField用法大全
//初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...
- IOS开发 - TextField 控件详细
//初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...
- Inspector a ProgressBar(定制属性面板)
一.定制进度条 这篇文章主要学习如何在Unity的Inspector中使用ProgressBar 普通属性面板预览 通常我们的属性面板如下 定制属性面板预览 而通过扩展成ProcessBar后 二.内 ...
- Django admin的一些有用定制
Model实例,myapp/models.py: from django.db import models class Blog(models.Model): name = models.CharFi ...
- IOS TextField设置大全
//初始化textfield并设置位置及大小 //设置边框样式,只有设置了才会显示边框样式 text.borderStyle = UITextBorderStyleRoundedRect; ...
- 定制ckeditor的菜单
修改配置文件config.js来定制cheditor的菜单,需要以下步骤: 1.找到ckeditor安装目录的config.js文件 2.记下要使用的功能名,以下的"-"代表分隔符 ...
- TextField控件详解2
//初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...
- 转发:iOS之textfield用法大全
转发至:http://m.blog.csdn.net/article/details?id=8121915 //初始化textfield并设置位置及大小 UITextField *text = [[U ...
- UIAlertController中TextField的用法
这时候可以添加如下代码: [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { // 可以 ...
随机推荐
- 通过GWT RPC实现客户端与服务器端的交互
GWT有两种与服务端进行交互的技术:GWT RPC和基于普通AJAX的远程交互技术.这里只介绍GWT RPC技术. 一个完整的RPC服务至少包含三个Java文件: 1.客户端远程接口类,需要继承Rem ...
- Bootstrap-基于jquery的bootstrap在线文本编辑器插件Summernote
Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器.Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox.Op ...
- java 递归函数
一.递归函数,通俗的说就是函数本身自己调用自己... 如:n!=n(n-1)! 你定义函数f(n)=nf(n-1) 而f(n-1)又是这个定义的函数..这就是递归 二.为什么要用递归:递归的目 ...
- ListBox重绘
.NET Framework 类库 ListBox.ItemHeight 属性 当 DrawMode 属性设置为 DrawMode.OwnerDrawFixed 时,所有项具有相同的高度.当 Dra ...
- IOS开发之网络开发工具
IOS开发之网络开发工具 做移动端开发 常常会涉及到几个模块:1.网络检測 2.网络请求get和post请求 3.文件上传 4.文件下载 5.断点续传 如今将这些一一分享给大家 ,也欢迎 ...
- Visual Studio Package 插件开发
背景 这段时间公司新做了一个支付系统,里面有N个后台服务,每次有更新修改,拷贝打包发布包"不亦乐乎"...于是我想要不要自己定制个打包插件. 部分朋友可能会认为,有现成的可以去找一 ...
- 3行3列表格 table实现,div+css实现
table实现: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- request对象多种方法封装表单数据
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...
- 使用Git操作GitHub代码入门教程
GitHub除了网页操作外,还可以借助本地客户端git(或github for windows)来增删修改远程代码.使用Git操作来连接GitHub可以通过Https或SSH方式,使用SSH方式可以免 ...
- 项目打包 weblogic部署
工作流打包: 由于没有集成单点,配置文件要修改 将webnocas.xml内容复制覆盖 web.xml 到这里修改完毕 选择weblogic项目,右键maven install,生成.ear文 ...