2014-08-05 11:00 447人阅读 评论(0) 收藏 举报

 分类:
IOS开发笔记(248) 

版权声明:本CSDN博客所有文章不会即时更新,请关注个人博客:http://www.huangyibiao.com/

  1. //
  2. //  HYBTextField.h
  3. //  CloudShopping
  4. //
  5. //  Created by sixiaobo on 14-7-10.
  6. //  Copyright (c) 2014年 com.Uni2uni. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. /*!
  10. * @brief 自定义TextField,用于修改默认textfield的属性为我们工程中需要的属性
  11. * @author huangyibiao
  12. */
  13. @interface HYBTextField : UITextField
  14. @property (nonatomic, strong) UIColor *placeholderColor;
  15. @property (nonatomic, strong) UIFont  *placeholderFont;
  16. @property (nonatomic, assign) CGFloat leftPadding;
  17. // 默认leftPadding = 8.0
  18. - (id)initWithFrame:(CGRect)frame placeholderColor:(UIColor *)color font:(UIFont *)font;
  19. - (id)initWithFrame:(CGRect)frame placeholderColor:(UIColor *)color font:(UIFont *)font leftPadding:(CGFloat)leftPadding;
  20. @end
  1. //
  2. //  HYBTextField.m
  3. //  CloudShopping
  4. //
  5. //  Created by sixiaobo on 14-7-10.
  6. //  Copyright (c) 2014年 com.Uni2uni. All rights reserved.
  7. //
  8. #import "HYBTextField.h"
  9. @implementation HYBTextField
  10. - (id)initWithFrame:(CGRect)frame placeholderColor:(UIColor *)color font:(UIFont *)font {
  11. return [self initWithFrame:frame placeholderColor:color font:font leftPadding:8];
  12. }
  13. - (id)initWithFrame:(CGRect)frame
  14. placeholderColor:(UIColor *)color
  15. font:(UIFont *)font
  16. leftPadding:(CGFloat)leftPadding {
  17. if (self = [super initWithFrame:frame]) {
  18. self.placeholderColor = color;
  19. self.placeholderFont = font;
  20. self.leftPadding = leftPadding;
  21. self.autocapitalizationType = UITextAutocapitalizationTypeNone;
  22. self.autocorrectionType = UITextAutocorrectionTypeNo;
  23. self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  24. self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  25. self.borderStyle = UITextBorderStyleNone;
  26. self.backgroundColor = [UIColor whiteColor];
  27. }
  28. return self;
  29. }
  30. - (void)drawPlaceholderInRect:(CGRect)rect {
  31. [kColorWith16RGB(0xa8a8a8) setFill];
  32. [[self placeholder] drawInRect:CGRectMake(self.leftPadding, rect.origin.y, rect.size.width, rect.size.height)
  33. withFont:self.placeholderFont];
  34. return;
  35. }
  36. // 控制编辑文本的位置
  37. - (CGRect)editingRectForBounds:(CGRect)bounds {
  38. CGFloat padding = self.leftPadding;
  39. if (self.textAlignment == NSTextAlignmentRight) {
  40. padding = 0;
  41. }
  42. CGRect inset = CGRectMake(bounds.origin.x + padding, bounds.origin.y,
  43. bounds.size.width, bounds.size.height);
  44. return inset;
  45. }
  46. - (CGRect)placeholderRectForBounds:(CGRect)bounds {
  47. NSString *obtainSizeString = self.text;
  48. CGSize size = [obtainSizeString sizeWithFont:self.placeholderFont];
  49. return CGRectMake(bounds.origin.x, (bounds.size.height - size.height) / 2,
  50. bounds.size.width, bounds.size.height);
  51. }
  52. // 控制显示文本的位置
  53. - (CGRect)textRectForBounds:(CGRect)bounds {
  54. CGFloat padding = self.leftPadding;
  55. if (self.textAlignment == NSTextAlignmentRight) {
  56. padding = 0;
  57. }
  58. CGRect inset = CGRectMake(bounds.origin.x + padding, bounds.origin.y,
  59. bounds.size.width, bounds.size.height);
  60. return inset;
  61. }
  62. @end

定制textField的更多相关文章

  1. iOS TextField用法大全

    //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...

  2. IOS开发 - TextField 控件详细

    //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...

  3. Inspector a ProgressBar(定制属性面板)

    一.定制进度条 这篇文章主要学习如何在Unity的Inspector中使用ProgressBar 普通属性面板预览 通常我们的属性面板如下 定制属性面板预览 而通过扩展成ProcessBar后 二.内 ...

  4. Django admin的一些有用定制

    Model实例,myapp/models.py: from django.db import models class Blog(models.Model): name = models.CharFi ...

  5. IOS TextField设置大全

    //初始化textfield并设置位置及大小  //设置边框样式,只有设置了才会显示边框样式     text.borderStyle = UITextBorderStyleRoundedRect; ...

  6. 定制ckeditor的菜单

    修改配置文件config.js来定制cheditor的菜单,需要以下步骤: 1.找到ckeditor安装目录的config.js文件 2.记下要使用的功能名,以下的"-"代表分隔符 ...

  7. TextField控件详解2

    //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...

  8. 转发:iOS之textfield用法大全

    转发至:http://m.blog.csdn.net/article/details?id=8121915 //初始化textfield并设置位置及大小 UITextField *text = [[U ...

  9. UIAlertController中TextField的用法

    这时候可以添加如下代码: [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { // 可以 ...

随机推荐

  1. 对tomcat来说,每一个进来的请求(request)都需要一个线程,直到该请求结束。

    这段时间折腾了哈java web应用的压力测试,部署容器是tomcat 7.期间学到了蛮多散碎的知识点,及时梳理总结,构建良好且易理解的知识架构把它们组织起来,以备忘.对web应用开发者来说,我们很关 ...

  2. MVC Controller return 格式

    所看到的Action都是return View();我们可以看作这个返回值用于解析一个aspx文件.而它的返回类型是ActionResult如 public ActionResult Index()  ...

  3. HTML里面Textarea换行总结

    近期碰到一个数据转来转去转到Textrea里面能否真正按行存放的问题,在这里总结一下:   问题描写叙述: 比方get数据到一个TextArea里面,如“AAA BBB”,想把这段文字在TextAre ...

  4. 关于Opengl中将24位BMP图片加入�一个alpha通道并实现透明的问题

    #include <windows.h>#include <GL/glut.h>#include <GL/glaux.h>#include <stdio.h& ...

  5. Apache Kafka: Next Generation Distributed Messaging System---reference

    Introduction Apache Kafka is a distributed publish-subscribe messaging system. It was originally dev ...

  6. Java基础知识强化之集合框架笔记59:Map集合之TreeMap(TreeMap<String,String>)的案例

    1. TreeMap类的概述: 键是红黑树结构,可以保证键的排序和唯一性. 2. TreeMap案例: TreeMap<String, String> 代码示例: package cn.i ...

  7. 【Android】数据存储-java IO流文件存储

    1.数据持久化:将在内存中的瞬时数据保存在存储设备中.瞬时数据:设备关机数据丢失.持久化技术提供一种机制可以让数据在瞬时状态和持久状态之间转换. 2.Android中简单的三种存储方式:文件存储.Sh ...

  8. chmod -R o+rX /data

    When using  chmod -R o+rx /data , you set the execute permission on all directories as well as files ...

  9. PLSQL Developer操作

    1.设置 1)下载32位Oracle InstantClient  2)将Oracle InstantClient解压到某目录  3)设置环境变量(修改NLS_LANG和TNS_ADMIN环境变量)对 ...

  10. 请问JAVA三层架构,持久层,业务层,表现层,都该怎么理解?和MVC三层模型有什么区别

    持久层用来固化数据,如常说的DAO层,操作数据库将数据入库业务层用来实现整体的业务逻辑 如 前台获得了数据,逻辑层去解析这些数据,效验这些数据等操作表现层很好解释  你现在看到的网页 一些界面 都属于 ...