UITextField设置leftView的Insets
Insets就是css中的padding
我们给UITextField设置了leftView,目的是在文本输入框左側显示一个图标。可是在ios7里,这个图标会紧紧地挨着TextField的左边框,非常不美观,所以就希望设置一个Insets。可是直接设置ImageView的bounds不行,须要用以下这种方法:
@interface YLSTextField : UITextField -(id)initWithFrame:(CGRect)frame Icon:(UIImageView*)icon; @end
@implementation YLSTextField -(id)initWithFrame:(CGRect)frame Icon:(UIImageView*)icon
{
self = [super initWithFrame:frame];
if (self) {
self.leftView = icon;
self.leftViewMode = UITextFieldViewModeAlways;
}
return self;
} -(CGRect) leftViewRectForBounds:(CGRect)bounds {
CGRect iconRect = [super leftViewRectForBounds:bounds];
iconRect.origin.x += 10;// 右偏10
return iconRect;
} @end
UIImage *usernameImage = [UIImage imageNamed:@"user"];
UIImageView *usernameIcon = [[UIImageView alloc] initWithImage:usernameImage];
usernameIcon.frame = CGRectMake(0, 0, 20, 20); self.username = [[YLSTextField alloc] initWithFrame:CGRectMake(0, 0, 240, 30) Icon:usernameIcon];
self.username.placeholder = @"用户名";
self.username.borderStyle = UITextBorderStyleRoundedRect;
self.username.clearButtonMode = UITextFieldViewModeWhileEditing;
[self.username setKeyboardType:UIKeyboardTypeNumberPad];
关键就是定义UITextField的子类,并覆盖其leftViewRectForBounds方法
UITextField设置leftView的Insets的更多相关文章
- 给UITextField设置头或尾空白
有时候,我们需要在UITextField的头尾加入一些空白,如下图所示: 其中,黄色和红色部分代表空白. 实现起来,比较简单,只需要设置UITextField的leftView.leftViewMod ...
- uitextfield 设置为密码框显示
uitextfield 设置为密码框显示: 在xib中,将文本secure的复选框选中即可.
- (转)设置 UILabel 和 UITextField 的 Padding 或 Insets (理解UIEdgeInsets)
转自http://unmi.cc/uilable-uitextfield-padding-insets 主要是理解下UIEdgeInsets在IOS UI里的意义.靠,这货其实就是间隔,起个名字这么让 ...
- 设置 UILabel 和 UITextField 的 Padding 或 Insets (理解UIEdgeInsets)
转自http://unmi.cc/uilable-uitextfield-padding-insets 主要是理解下UIEdgeInsets在IOS UI里的意义. 靠,这货其实就是间隔,起个名字这么 ...
- UITextfield设置Placeholder颜色 控件 内边距、自适应高度
//创建UITextField对象 UITextField * tf=[[UITextField alloc]init]; //设置Placeholder颜色 [text setAttribut ...
- iOS UITextField设置placeholder颜色
设置UITextField的placeholder颜色 UIColor *color = [UIColor blackColor]; textField.attributedPlaceholder = ...
- iOS学习-UITextField设置placeholder的颜色
UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(, , , )]; text.borderStyle = UITex ...
- IOS UITextField 设置光标位置
textField.leftView = [[[UIView alloc] initWithFrame:CGRectMake(, , , )] autorelease]; textField.left ...
- UITextField设置密文延时处理---仿QQ登录密码输入
系统的UITextField输入的时候最后一个字符会有1-2s的效果展示, 效果如下: 为了解决这个问题, 可以用字符 "●" 替换, 替换后效果如下: 用到的是UITextFie ...
随机推荐
- 深度学习 Deep Learning UFLDL 最新Tutorial 学习笔记 4:Debugging: Gradient Checking
1 Gradient Checking 说明 前面我们已经实现了Linear Regression和Logistic Regression.关键在于代价函数Cost Function和其梯度Gradi ...
- ZOJ 1494 Climbing Worm 数学水题
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=494 题目大意: 一只蜗牛要从爬上n英寸高的地方,他速度为u每分钟,他爬完u需要 ...
- shell脚本if条件总结
原文链接:https://geniuspeng.github.io/2018/03/12/shell-if/ shell编程中,if-then是一种常见的控制流命令,而if的条件判断一般采用内置命令t ...
- WordPress的后台功能菜单介绍与操作,WordPress后台说明
WordPress网站的后台概况和登陆地址 网站都有个后台管理系统,通过网站后台,你可以改变你的网站外观,管理你网站的数据,给网站前台增加页面,文章,视频,图片或者其他功能. 通过WordPress建 ...
- 试用 Tomcat7.x 与 Tomcat6.x 的明显不同 + Context 填写方法 + 默认应用配置方法 (zhuan)
http://blog.csdn.net/shanelooli/article/details/7408675
- JasperReport html 导出
In my last blog post I discussed about Generating jasper reports in different formats using json fil ...
- Java 8新特性探究(十一)Base64详解
开发十年,就只剩下这套架构体系了! >>> BASE64 编码是一种常用的字符编码,在很多地方都会用到.但base64不是安全领域下的加密解密算法.能起到安全作用的效果很差,而且 ...
- 【poj3225】Help with Intervals
Time Limit: 6000MS Memory Limit: 131072K Total Submissions: 12084 Accepted: 3033 Case Time Limit ...
- unresolved external symbol __forceAtlDllManifest错误的解决
作者:朱金灿 来源:http://blog.csdn.net/clever101 晚上编译一个ATL程序,出现一些诡异的错误: 1>CGreet.obj : error LNK2001: unr ...
- 接入Erlang控制台的几种方法
在window中调试的时候我们可以通过启动多个cmd窗口运行Erlang节点,在生产环境中我们需要Erlang服务在Centos服务器上后台运行;这就需要在启动的时候添加启动参数detached来脱离 ...