有的时候,textField里面的文字展示,需要距离左边一定的间距,而不是直接从最左边开始,占位字的颜色也不是我们需要的,这时候我们就需要做一些操作:
// 改变占位文字颜色
NSMutableDictionary
*attrs = [NSMutableDictionarydictionary];
attrs[NSForegroundColorAttributeName]
=
XZColor(172,
172,
172);
attrs[NSFontAttributeName] = [UIFont systemFontOfSize:15];
textInputTitle.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"占位文字..." attributes:attrs];
textInputTitle.backgroundColor = [UIColor whiteColor];
// 左侧10个间距
CGRect frame = textInputTitle.frame;
frame.size.width = 10;// 距离左侧的距离
UIView *leftview = [[UIView alloc] initWithFrame:frame];
textInputTitle.leftViewMode = UITextFieldViewModeAlways;
attrs[NSFontAttributeName] = [UIFont systemFontOfSize:15];
textInputTitle.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"占位文字..." attributes:attrs];
textInputTitle.backgroundColor = [UIColor whiteColor];
// 左侧10个间距
CGRect frame = textInputTitle.frame;
frame.size.width = 10;// 距离左侧的距离
UIView *leftview = [[UIView alloc] initWithFrame:frame];
textInputTitle.leftViewMode = UITextFieldViewModeAlways;
textInputTitle.leftView
= leftview;
本文介绍如何在 iOS 开发中自定义 UITextField 的占位文字颜色、字体大小及设置左侧间距,实现更加美观的输入框样式。
1万+

被折叠的 条评论
为什么被折叠?



