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. 通过GWT RPC实现客户端与服务器端的交互

    GWT有两种与服务端进行交互的技术:GWT RPC和基于普通AJAX的远程交互技术.这里只介绍GWT RPC技术. 一个完整的RPC服务至少包含三个Java文件: 1.客户端远程接口类,需要继承Rem ...

  2. Bootstrap-基于jquery的bootstrap在线文本编辑器插件Summernote

    Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器.Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox.Op ...

  3. java 递归函数

    一.递归函数,通俗的说就是函数本身自己调用自己...  如:n!=n(n-1)!  你定义函数f(n)=nf(n-1)  而f(n-1)又是这个定义的函数..这就是递归  二.为什么要用递归:递归的目 ...

  4. ListBox重绘

    .NET Framework 类库  ListBox.ItemHeight 属性 当 DrawMode 属性设置为 DrawMode.OwnerDrawFixed 时,所有项具有相同的高度.当 Dra ...

  5. IOS开发之网络开发工具

    IOS开发之网络开发工具 做移动端开发  常常会涉及到几个模块:1.网络检測   2.网络请求get和post请求  3.文件上传  4.文件下载   5.断点续传 如今将这些一一分享给大家 ,也欢迎 ...

  6. Visual Studio Package 插件开发

    背景 这段时间公司新做了一个支付系统,里面有N个后台服务,每次有更新修改,拷贝打包发布包"不亦乐乎"...于是我想要不要自己定制个打包插件. 部分朋友可能会认为,有现成的可以去找一 ...

  7. 3行3列表格 table实现,div+css实现

    table实现: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  8. request对象多种方法封装表单数据

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...

  9. 使用Git操作GitHub代码入门教程

    GitHub除了网页操作外,还可以借助本地客户端git(或github for windows)来增删修改远程代码.使用Git操作来连接GitHub可以通过Https或SSH方式,使用SSH方式可以免 ...

  10. 项目打包 weblogic部署

    工作流打包:   由于没有集成单点,配置文件要修改 将webnocas.xml内容复制覆盖 web.xml   到这里修改完毕 选择weblogic项目,右键maven install,生成.ear文 ...