填充占位符文本ios [英] Padding Placeholder text ios

查看:25
本文介绍了填充占位符文本ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让占位符文本显示在文本字段的中间(填充占位符文本).占位符文本的大小也需要增加.我的代码如下,我该如何解决?

I want to make the placeholder text display in middle of the textfield (Padding placeholder text). The size of the placeholder text also needs to increase. My code is as follows, how can i solve this ?

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(30, 220,250,55)];

textField.placeholder=@"iiiiiii";

UIView *padView = [[UIView alloc] initWithFrame:CGRectMake(10, 110, 10, 0)];
textField.leftView = padView;
    textField.leftViewMode = UITextFieldViewModeAlways;


[self.view addSubview:textField];

更新

我希望占位符文本的字体大小增加你的名字,并且它应该有一个左边的填充.

I want the font size of the placeholder text to increase your name, and it should have a Left padding to it.

推荐答案

您可以子类化 UITextFiled 并覆盖方法:

You could subclass your UITextFiled and override methods:

MyTextField.m

- (CGRect)textRectForBounds:(CGRect)bounds {
    return [self rectForBounds:bounds];
}

- (CGRect)editingRectForBounds:(CGRect)bounds {
    return [self rectForBounds:bounds];
}

- (CGRect)placeholderRectForBounds:(CGRect)bounds {
    return [self rectForBounds:bounds];
}

//here 40 - is your x offset
- (CGRect)rectForBounds:(CGRect)bounds {
    return CGRectInset(bounds, 40, 3);
}

更新:也设置

textFiled.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

因为 io6 与 ios 7 垂直定位可能存在一些问题

because it could some problems with io6 vs ios 7 vertical positionning

这篇关于填充占位符文本ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆