最右侧加图片是以下代码,
UIImageView *imgv=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];
text.rightView=imgv;
text.rightViewMode = UITextFieldViewModeAlways;
如果是在最左侧加图片就换成:
text.leftView=imgv;
text.leftViewMode = UITextFieldViewModeAlways;
UITextField 继承自 UIControl,此类中有一个属性contentVerticalAlignment
所以想让UITextField里面的text垂直居中可以这样写:
text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
UITextField 垂直居 最右侧放图片
最新推荐文章于 2023-03-21 20:36:09 发布
本文介绍如何在 UITextField 中添加图片至最左或最右侧,并实现文本的垂直居中显示。通过简单代码示例,展示了如何使用 UIImageView 和 UITextField 的属性进行设置。

2718

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



