UITextField placeholder 文字居中

本文介绍如何使用Swift进行UITextField的样式设置,包括使占位符和文字居中显示、设置左侧视图等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// 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];




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值