// placeholder 居中显示
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.alignment = NSTextAlignmentCenter;
NSAttributedString *attri = [[NSAttributedString alloc] initWithString:@"采摘服务" attributes:@{NSForegroundColorAttributeName:RGBACOLOR(159, 159, 159, 1),NSFontAttributeName:[UIFont systemFontOfSize:15.0f], NSParagraphStyleAttributeName:style}];
textField.attributedPlaceholder = atria;
// 文字居中
textField.textAlignment = 1;(NSTextAlignmentCenter)
// leftView
UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@".png"]];
image.frame = CGRectMake(5.0f, 5.0f, 20.0f, 20.0f);
textField.leftView = image;
textField.leftViewMode = UITextFieldViewModeAlways;
textField.font = [UIFont systemFontOfSize:15.0f];
本文介绍如何使用Swift进行UITextField的样式设置,包括使占位符和文字居中显示、设置左侧视图等操作。
1万+

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



