有的时候,textField里面的文字展示,需要距离左边一定的间距,而不是直接从最左边开始,占位字的颜色也不是我们需要的,这时候我们就需要做一些操作:
// 改变占位文字颜色
NSMutableDictionary
*attrs = [
NSMutableDictionary
dictionary
];
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;