uitextfield 设置左图标以及图标文字间距,输入框背景图切换
2015-07-08 17:37
423 查看
参考网上资料,直接使用网上的代码,没有实现,重新修改
YLSTextField文件
页面中代码
输入框点击时背景图改变,不知道为啥在storyboard中设置的没有起作用。
YLSTextField文件
[code]#import <UIKit/UIKit.h> @interface YLSTextField : UITextField @end #import "YLSTextField.h" @implementation YLSTextField //改变文字位置 -(CGRect) textRectForBounds:(CGRect)bounds{ CGRect iconRect=[super textRectForBounds:bounds]; iconRect.origin.x+=10; return iconRect; } //改变编辑时文字位置 -(CGRect) editingRectForBounds:(CGRect)bounds{ CGRect iconRect=[super editingRectForBounds:bounds]; iconRect.origin.x+=10; return iconRect; } @end
页面中代码
[code]self.loginuser.delegate=self; self.loginpass.delegate=self; //设置输入框左边图标 UIImageView *image1=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"user.png"]]; image1.frame=CGRectMake(0, 0, 27, 27); self.loginuser.leftView=image1; self.loginuser.leftViewMode=UITextFieldViewModeAlways; UIImageView *image2=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mima.png"]]; image2.frame=CGRectMake(0, 0, 27, 27); self.loginpass.leftView=image2; self.loginpass.leftViewMode=UITextFieldViewModeAlways;
输入框点击时背景图改变,不知道为啥在storyboard中设置的没有起作用。
[code]//改变输入框背景图片 -(void)textFieldDidBeginEditing:(YLSTextField *)textField{ if (textField.tag==3) { [self.loginuser setBackground:[UIImage imageNamed:@"inputlan.png"]]; }else if(textField.tag==4){ [self.loginpass setBackground:[UIImage imageNamed:@"inputlan.png"]]; } } -(void)textFieldDidEndEditing:(YLSTextField *)textField{ if (textField.tag==3) { [self.loginuser setBackground:[UIImage imageNamed:@"inputhui.png"]]; }else if(textField.tag==4){ [self.loginpass setBackground:[UIImage imageNamed:@"inputhui.png"]]; } }
相关文章推荐
- UITextField 在tableView中键盘弹出问题
- 得到UILable在设置字体样式后的真实长度
- IOS疯狂基础之UILabel
- 使用Android-BluetoothSPPLibrary自动连接蓝牙设备
- UITextView 居中变为居上
- UITableView 自带编辑删除 自定义按钮
- request.META里包含了哪些数据?
- 获取UUID两种方法,并让UUID唯一的方法
- Android之Handler、MessageQueue、Message、Messager与Looper关系
- 学习easyui疑问(三)
- UIButton 转化为 UIBarButtonItem
- PHP中include require include_once require_once 的区别
- Fuel 30 分钟快速安装OpenStack
- Goagent Install Guide
- UE的相关操作
- phoenixframe自动化测试平台webUI用例实例
- iOS UIButton在某些情况下不能立刻响应TouchDown事件
- UVA 1324 The Largest Clique 最大团(强连通分量,变形)
- Java String StringBuilder 和 StringBuffer 用法详解
- The way it is connected with wristwatches connected with almost any bunch of Diesel-engined is unique