定制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) { // 可以 ...
随机推荐
- 对tomcat来说,每一个进来的请求(request)都需要一个线程,直到该请求结束。
这段时间折腾了哈java web应用的压力测试,部署容器是tomcat 7.期间学到了蛮多散碎的知识点,及时梳理总结,构建良好且易理解的知识架构把它们组织起来,以备忘.对web应用开发者来说,我们很关 ...
- MVC Controller return 格式
所看到的Action都是return View();我们可以看作这个返回值用于解析一个aspx文件.而它的返回类型是ActionResult如 public ActionResult Index() ...
- HTML里面Textarea换行总结
近期碰到一个数据转来转去转到Textrea里面能否真正按行存放的问题,在这里总结一下: 问题描写叙述: 比方get数据到一个TextArea里面,如“AAA BBB”,想把这段文字在TextAre ...
- 关于Opengl中将24位BMP图片加入�一个alpha通道并实现透明的问题
#include <windows.h>#include <GL/glut.h>#include <GL/glaux.h>#include <stdio.h& ...
- Apache Kafka: Next Generation Distributed Messaging System---reference
Introduction Apache Kafka is a distributed publish-subscribe messaging system. It was originally dev ...
- Java基础知识强化之集合框架笔记59:Map集合之TreeMap(TreeMap<String,String>)的案例
1. TreeMap类的概述: 键是红黑树结构,可以保证键的排序和唯一性. 2. TreeMap案例: TreeMap<String, String> 代码示例: package cn.i ...
- 【Android】数据存储-java IO流文件存储
1.数据持久化:将在内存中的瞬时数据保存在存储设备中.瞬时数据:设备关机数据丢失.持久化技术提供一种机制可以让数据在瞬时状态和持久状态之间转换. 2.Android中简单的三种存储方式:文件存储.Sh ...
- chmod -R o+rX /data
When using chmod -R o+rx /data , you set the execute permission on all directories as well as files ...
- PLSQL Developer操作
1.设置 1)下载32位Oracle InstantClient 2)将Oracle InstantClient解压到某目录 3)设置环境变量(修改NLS_LANG和TNS_ADMIN环境变量)对 ...
- 请问JAVA三层架构,持久层,业务层,表现层,都该怎么理解?和MVC三层模型有什么区别
持久层用来固化数据,如常说的DAO层,操作数据库将数据入库业务层用来实现整体的业务逻辑 如 前台获得了数据,逻辑层去解析这些数据,效验这些数据等操作表现层很好解释 你现在看到的网页 一些界面 都属于 ...