iOS以编程方式将左图像添加到Xcode中的UITextField?

ros*_*ely -1 xcode objective-c uitextfield ios swift

**

iOS以编程方式将左图像添加到Xcode中的UITextField?

**

1)我想以一个UIviewWhite Background color,里面View添加的我 4 Textfield's

2)我想添加4 different imagesleft side4 different textfields内部View具有以下特性?

视图的特性 i)corner Radius--- 5 ii)Border Color----light Gray Color

3)如何添加Space之间imagePlaceholder Text内部的Textfields从下面的图中,也add layerall textfieldslight gray color

我怎么能实现这个????

视图结合Textfields和图像这样

Anb*_*hik 5

UIImageView *imgforLeft=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)]; // Set frame as per space required around icon
[imgforLeft setImage:[UIImage imageNamed:@"yourImagename.png"]];

[imgforLeft setContentMode:UIViewContentModeCenter];// Set content mode centre or fit 

self. yourTextfield.leftView=imgforLeft;
self. yourTextfield.leftViewMode=UITextFieldViewModeAlways;
Run Code Online (Sandbox Code Playgroud)

选择-2

// short answer with out 
self. yourTextfield.leftViewMode = UITextFieldViewModeAlways;
self. yourTextfield.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImagename.png"]];
Run Code Online (Sandbox Code Playgroud)

迅速

self. yourTextfield.leftViewMode = UITextFieldViewMode.Always
self. yourTextfield.leftView = UIImageView(image: UIImage(named: "yourImagename.png"))
Run Code Online (Sandbox Code Playgroud)

更新

for TextField1

UIImageView *imgforLeft1=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)]; // Set frame as per space required around icon
[imgforLeft1 setImage:[UIImage imageNamed:@"yourImagename1.png"]];

[imgforLeft1 setContentMode:UIViewContentModeCenter];// Set content mode centre or fit 

self. yourTextfield1.leftView=imgforLeft1;
self. yourTextfield1.leftViewMode=UITextFieldViewModeAlways;

  self. yourTextfield1.layer.sublayerTransform = CATransform3DMakeTranslation(30, 0, 0);
Run Code Online (Sandbox Code Playgroud)

对于TextField2

UIImageView *imgforLeft2=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)]; // Set frame as per space required around icon
[imgforLeft2 setImage:[UIImage imageNamed:@"yourImagename2.png"]];

[imgforLeft1 setContentMode:UIViewContentModeCenter];// Set content mode centre or fit 

self. yourTextfield2.leftView=imgforLeft1;
self. yourTextfield2.leftViewMode=UITextFieldViewModeAlways;

   self. yourTextfield2.layer.sublayerTransform = CATransform3DMakeTranslation(30, 0, 0);
Run Code Online (Sandbox Code Playgroud)

对于TextField3

UIImageView *imgforLeft3=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)]; // Set frame as per space required around icon
[imgforLeft3 setImage:[UIImage imageNamed:@"yourImagename3.png"]];

[imgforLeft3 setContentMode:UIViewContentModeCenter];// Set content mode centre or fit 

self. yourTextfield3.leftView=imgforLeft1;
self. yourTextfield3.leftViewMode=UITextFieldViewModeAlways;

  self. yourTextfield3.layer.sublayerTransform = CATransform3DMakeTranslation(30, 0, 0);
Run Code Online (Sandbox Code Playgroud)

对于TextField4

UIImageView *imgforLeft4=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)]; // Set frame as per space required around icon
[imgforLeft4 setImage:[UIImage imageNamed:@"yourImagename4.png"]];

[imgforLeft4 setContentMode:UIViewContentModeCenter];// Set content mode centre or fit 

self. yourTextfield4.leftView=imgforLeft1;
self. yourTextfield4.leftViewMode=UITextFieldViewModeAlways;

  self. yourTextfield4.layer.sublayerTransform = CATransform3DMakeTranslation(30, 0, 0);
Run Code Online (Sandbox Code Playgroud)