如何在ios中从5像素输入文本字段中的文本

时间:2013-05-17 11:05:41

标签: iphone ios uitextfield text-alignment

我有UITextField我添加了一张图片。

一切看起来都不错,除了文本从零X坐标开始,但我希望它在文本字段中的5个像素之后开始。

4 个答案:

答案 0 :(得分:0)

将左视图放入文本字​​段:

    textField.layer.cornerRadius = 5.0;
    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, textField.frame.size.height)];
    textField.leftView = paddingView;
    [paddingView release];
    textField.leftViewMode = UITextFieldViewModeAlways;

答案 1 :(得分:0)

这样做的简单方法。

  • 添加textfeld的图片
  • 添加自定义类型的uitextfield
  • 设置添加的uitextfield&的框架向右移动5个像素而不是图像

结帐附加图片以获取详细知识

In attached picture you can see gray is an image for the textfield, & inside it I've added textfield 5 px right from gray image with type roundrect, just for the understanding purpose, you have to ake custom type

享受编程!

答案 2 :(得分:0)

最简单的答案:

1)选择一个UIImageView。在UITextField中为UIImageView添加该图片。

2)添加UITextField “无边框”高于UIImageViewUIImageView右侧5个像素)。

GoodLuck !!!

答案 3 :(得分:0)

尝试使用此

  UIImageView *imageView = [[UIImageView alloc] init];

    // add 5 (width) pixel for your space
    imageView.frame = CGRectMake(0,0 ,5, txtFld.frame.size.height);

    txtFld.leftViewMode = UITextFieldViewModeAlways;
    txtFld.leftView = imageView;

请参阅此图片以获取更多信息。

enter image description here