定制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) { // 可以 ...
随机推荐
- 调试postgresql9.5.2最新源码
最近在考量数据库的选型,考虑后期把数据切换到postgresql ,postgresql源码用c实现,代码很精炼完美,值得学习下 首先去pgsql官网下载最新的源码 ,然后还需要perl,bison ...
- XMind十大最有用的功能
XMind十大最有用的功能 XMind是一款顶级商业品质的思维导图软件和头脑风暴软件,在企业和教育领域都有很广泛的应用,XMind功能全面,易上手,在此小编给大家整理出了XMind十大最有用的功能以供 ...
- Jupyter Notebook PDF输出的中文支持
Jupyter Notebook是什么 Jupyter Notebook是ipython Notebook 的升级.Jupyter能够将实时代码,公式,可视化图表以Cell的方式组织在一起,形成一个对 ...
- JS获取和设置光标的位置
<html> <head> <script language="javascript"> function getCursortPosition ...
- 2014-08-05 pig
Pig的数据类型能够分为两种:一种是scalar类型,包含单一的value,一种是complex类型,包含有其他的类型. 对于scalar类型: int,long,float,double,chara ...
- Windows下Memcached在.Net程序中的实际运用(从Memcached客户端Enyim的库的编译到实际项目运用)
1.一点基础概念 2.获取EnyimMemcached客户端的源代码并编译出动态库 3.Memcached的服务器安装(windows server) 4.在web项目中实战 一.基础概念 memca ...
- j2ee学习笔记 Filter过滤器
作用:过滤response和request对象的内容 使用: Filter是J2EE的一个接口,自定义Filter需要实现该接口,并重写所有的方法. Filter提供的方法: init() doFil ...
- my_pnd_start
终于有个雏形了,再给自己一些时间做做看吧.
- 程序员带你十天快速入门Python,玩转电脑软件开发(四)
本系列文章立志于从一个已经习得一门编程语言的基础之上,全面介绍Python的相关开发过程和相关经验总结.本篇文章主要是基于上一篇的程序员带你十天快速入门Python,玩转电脑软件开发(三)的基础之上, ...
- CSS画三角形引发的一些思考
今天刷知乎时看到了一个问题,有谁能详细讲一下css如何画出一个三角形?怎么想都想不懂? - 知乎.很巧,刚入前端坑的我前不久也遇到过这个问题,今天再来谈一谈这个问题则是因为知乎的一些答案引发了我的 ...