定制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) { // 可以 ...
随机推荐
- ios xcode如何在控制台打印frame
进入正题 打开终端输入三条命令: 1. touch ~/.lldbinit 2. echo display @import UIKit >> ~/.lldbinit 3. echo tar ...
- js 设置cookie
function GetCookieVal(offset) // 获得Cookie解码后的值 { var endstr = document.cookie.indexOf(";", ...
- java-常用快捷键
alt+/:代码提示 ctrl+/:代码提示 ctrl+1:快速生成impl代码
- 查看LINUX发行商版本与LINUX内核版本
查看LINUX发行商版本:[root@server-mysql ~]# cat /etc/issue Red Hat Enterprise Linux Server release 6.3 (Sant ...
- hadoop错误org.apache.hadoop.yarn.exceptions.YarnException Unauthorized request to start container
错误: 14/04/29 02:45:07 INFO mapreduce.Job: Job job_1398704073313_0021 failed with state FAILED due to ...
- JAVA 上加密算法的实现用例---转载
通常 , 使用的加密算法 比较简便高效 , 密钥简短,加解密速度快,破译极其困难.本文介绍了 MD5/SHA1,DSA,DESede/DES,Diffie-Hellman 的使用. 第 1 章基础知识 ...
- 基于Lucene的文件检索Demo
通过Lucene实现了简单的文件检索功能的Demo.这个Demo支持基于文件内容的检索,支持中文分词和高亮显示. 下面简单的介绍下核心的类 1)索引相关的类 1.FileIndexBuilder -- ...
- ubuntu权限管理常用命令 分类: linux ubuntu 学习笔记 2015-07-05 14:15 77人阅读 评论(0) 收藏
1.chmod 第一种方式 chomd [{ugoa}{+-=}{rwx}] [文件或者目录] u 代表该文件所属用户 g 代表该文件所属用户组 o 代表访客 a 代表所有用户 +-=分别表示增加权限 ...
- Oracle 插入数据效率对比
oracle插入数据有多种方式: 将从多个表中查出来的数据插入到临时表中 数据行数 5189597 1.传统方式:直接将数据插入到表中 insert into LLB_BASIC_USER_D_TEM ...
- linux sed使用
原文引用:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856901.html [root@www ~]# sed [-nefr] [动作] ...