IOS界面开发UItextField定制全局组件_自定文字左边距、图标

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

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

-(void)setTextFieldLeftPadding:(UITextField *)textField forWidth:(CGFloat)leftWidth
{
    CGRect frame = textField.frame;
    frame.size.width = leftWidth;
    UIView *leftview = [[UIView alloc] initWithFrame:frame];
    textField.leftViewMode = UITextFieldViewModeAlways;
    textField.leftView = leftview;
}


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

//最右侧加图片是以下代码  左侧类似
    UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];
    text.rightView=image;
    text.rightViewMode = UITextFieldViewModeAlways; 
 
typedef enum {
    UITextFieldViewModeNever,
    UITextFieldViewModeWhileEditing,
    UITextFieldViewModeUnlessEditing,
    UITextFieldViewModeAlways
} UITextFieldViewMode;
 
3.在头文件里定制全局变量:

#import <UIKit/UIKit.h>

@interface appstoreViewController : UIViewController
@property (strong, nonatomic) UIButton *osButton1;
@property (strong, nonatomic) UIButton *osButton2;
@end

4.修改默认字体颜色

//第一种   
   
 UIColor *color = [UIColor whiteColor];  
    _userName.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用户名" attributes:@{NSForegroundColorAttributeName: color}];  
  
  
//第二种   
[_userName setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];

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

 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、付费专栏及课程。

余额充值