iOS 以编程方式将左图像添加到 Xcode 中的 UITextField? [英] iOS Programmatically Add Left image to UITextField in Xcode?
问题描述
**
iOS 以编程方式将左图添加到 Xcode 中的 UITextField?
iOS Programmatically Adding Left image to UITextField in Xcode?
**
1) 我想要一个带有 White Background color
的 UIview
,在 View
里面我添加了 4 Textfield's
?
1) I want Take a UIview
with White Background color
, inside the View
i added 4 Textfield's
?
2) 我想将 4 个不同的图像
添加到 View
内 4 个不同文本字段
的 左侧
代码>具有以下属性?
2) I want to add 4 different images
to the left side
of the 4 different textfields
inside a View
Having following properties?
要查看的属性i) 拐角半径
---5
ii) Border Color
----浅灰色
Properties For View
i) corner Radius
---5
ii) Border Color
----light Gray Color
3) 如何在下图中的Textfields
中的image
和Placeholder Text
之间添加Space
以及 add layer
for all textfields
with light gray color
?
3) How to add Space
between the image
and Placeholder Text
inside the Textfields
from the below figure and also add layer
for all textfields
with light gray color
?
我怎样才能做到这一点????
How can i Achieve this ????
The View Combined With Textfields
and Images like this
推荐答案
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;
选择 -2
// short answer with out
self. yourTextfield.leftViewMode = UITextFieldViewModeAlways;
self. yourTextfield.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourImagename.png"]];
迅捷
self. yourTextfield.leftViewMode = UITextFieldViewMode.Always
self. yourTextfield.leftView = UIImageView(image: UIImage(named: "yourImagename.png"))
更新
对于 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);
对于 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);
对于 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);
对于 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);
这篇关于iOS 以编程方式将左图像添加到 Xcode 中的 UITextField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!