uitextfield 设置左图标以及图标文字间距,输入框背景图切换
来源:互联网 发布:新浪php面试题及答案 编辑:程序博客网 时间:2024/05/17 17:46
参考网上资料,直接使用网上的代码,没有实现,重新修改
YLSTextField文件
#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
页面中代码
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中设置的没有起作用。
//改变输入框背景图片-(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"]]; }}
0 1
- uitextfield 设置左图标以及图标文字间距,输入框背景图切换
- iPhone UIButton图标与文字间距设置
- iPhone UIButton 图标与文字间距设置
- iPhone UIButton图标与文字间距设置【转】
- iPhone UIButton图标与文字间距设置【转】
- iPhone UIButton图标与文字间距设置【转】
- 给UITextField设置图标
- UITextField 左图以及文字位置的设置
- iOS - 设置Iconfont文字“图标”
- 关于UITextField左侧图标的设置
- Android BottomNavigationBar底部导航控制器图标和文字间距调整
- TextView设置文字间距以及识别电话
- 动态为TextView控件设置drawableLeft图标,并设置间距
- 文字图标
- Android设置圆形组件以及在组件中设置图标或文字的2中方法
- Android 自定义 TextView drawableTop 图标与文字左对齐(效果图)
- bootstrap之表单输入框以及图标的使用
- ios button 图标和文字位置设置
- 图标收藏
- sqlmap使用笔记
- SPRING+JUNIT单元测试s
- hadoop一些基本知识——Hadoop reducer类的阅读
- 算法之二叉树各种遍历
- uitextfield 设置左图标以及图标文字间距,输入框背景图切换
- jquery设置元素的readonly和disabled
- CGContext用法详解
- cell去重 覆盖代码
- 台大机器学习基石笔记(三)——VC 维2
- 2012年5月SAT香港真题解析
- 96 n-1位数
- 五、Oracle表查询一
- linux周期性执行程序命令crontab