【iOS学习笔记】界面开发UItextField定制全局组件_自定文字左边距、图标

在开发系统登录界面的时候遇到定制UItextField的问题,结合上午的使用定制全局变量的案例总结代码如下:

1.定义UItextField文字的左边距,代码如下:

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. -(void)setTextFieldLeftPadding:(UITextField *)textField forWidth:(CGFloat)leftWidth  
  2. {  
  3.     CGRect frame = textField.frame;  
  4.     frame.size.width = leftWidth;  
  5.     UIView *leftview = [[UIView alloc] initWithFrame:frame];  
  6.     textField.leftViewMode = UITextFieldViewModeAlways;  
  7.     textField.leftView = leftview;  
  8. }  


 
2.定义UItextField的图标,代码如下: 

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. //最右侧加图片是以下代码  左侧类似  
  2.     UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];  
  3.     text.rightView=image;  
  4.     text.rightViewMode = UITextFieldViewModeAlways;   
  5.    
  6. typedef enum {  
  7.     UITextFieldViewModeNever,  
  8.     UITextFieldViewModeWhileEditing,  
  9.     UITextFieldViewModeUnlessEditing,  
  10.     UITextFieldViewModeAlways  
  11. } UITextFieldViewMode;  
  12.    
3.在头文件里定制全局变量:

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. #import <UIKit/UIKit.h>  
  2.   
  3. @interface appstoreViewController : UIViewController  
  4. @property (strongnonatomicUIButton *osButton1;  
  5. @property (strongnonatomicUIButton *osButton2;  
  6. @end  

4.修改默认字体颜色

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. //第一种     
  2.      
  3.  UIColor *color = [UIColor whiteColor];    
  4.     _userName.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用户名" attributes:@{NSForegroundColorAttributeName: color}];    
  5.     
  6.     
  7. //第二种     
  8. [_userName setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];  

5.UIColor的使用RGB三色来表示颜色,RGB的颜色值范围都是在0.0~1.0之间的

[objc]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. UIColor *color = [UIColor colorWithRed:145.0/255.0 green:151.0/255.0 blue:151.0/255.0 alpha:1
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值