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. ios xcode如何在控制台打印frame

    进入正题 打开终端输入三条命令: 1. touch ~/.lldbinit 2. echo display @import UIKit >> ~/.lldbinit 3. echo tar ...

  2. js 设置cookie

    function GetCookieVal(offset) // 获得Cookie解码后的值 { var endstr = document.cookie.indexOf(";", ...

  3. java-常用快捷键

    alt+/:代码提示 ctrl+/:代码提示 ctrl+1:快速生成impl代码

  4. 查看LINUX发行商版本与LINUX内核版本

    查看LINUX发行商版本:[root@server-mysql ~]# cat /etc/issue Red Hat Enterprise Linux Server release 6.3 (Sant ...

  5. 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 ...

  6. JAVA 上加密算法的实现用例---转载

    通常 , 使用的加密算法 比较简便高效 , 密钥简短,加解密速度快,破译极其困难.本文介绍了 MD5/SHA1,DSA,DESede/DES,Diffie-Hellman 的使用. 第 1 章基础知识 ...

  7. 基于Lucene的文件检索Demo

    通过Lucene实现了简单的文件检索功能的Demo.这个Demo支持基于文件内容的检索,支持中文分词和高亮显示. 下面简单的介绍下核心的类 1)索引相关的类 1.FileIndexBuilder -- ...

  8. ubuntu权限管理常用命令 分类: linux ubuntu 学习笔记 2015-07-05 14:15 77人阅读 评论(0) 收藏

    1.chmod 第一种方式 chomd [{ugoa}{+-=}{rwx}] [文件或者目录] u 代表该文件所属用户 g 代表该文件所属用户组 o 代表访客 a 代表所有用户 +-=分别表示增加权限 ...

  9. Oracle 插入数据效率对比

    oracle插入数据有多种方式: 将从多个表中查出来的数据插入到临时表中 数据行数 5189597 1.传统方式:直接将数据插入到表中 insert into LLB_BASIC_USER_D_TEM ...

  10. linux sed使用

    原文引用:http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856901.html [root@www ~]# sed [-nefr] [动作] ...