如何在UITextField的开头添加空间 [英] How to add space at start of UITextField

查看:150
本文介绍了如何在UITextField的开头添加空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含多个 UITextField 的应用。在textField中,我将边框类型设置为无和背景图像。它显示正常,但现在我的文本是从最小的边框开始看起来不太好,比如这个

I am creating an app that contain multiple UITextField. In the textField i have sated border type to none and background image. It display fine, But now my text is started from the lest border which does not look good, like this

如何在文本字段的开头添加空格?

How can i add space at the start of the textfield?

推荐答案

试试这个

UILabel * leftView = [[UILabel alloc] initWithFrame:CGRectMake(10,0,7,26)];
leftView.backgroundColor = [UIColor clearColor];

textField.leftView = leftView;

textField.leftViewMode = UITextFieldViewModeAlways;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

这篇关于如何在UITextField的开头添加空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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