gpt4 book ai didi

ios - iOS7 上的 UITextfield leftView/rightView 填充

转载 作者:IT老高 更新时间:2023-10-28 11:21:44 27 4
gpt4 key购买 nike

iOS7 上 UITextField 的 leftView 和 rightView View 非常接近文本框的边框。

如何为这些项目添加一些(水平)填充?

我尝试修改框架,但没有成功

uint padding = 10;//padding for iOS7
UIImageView * iconImageView = [[UIImageView alloc] initWithImage:iconImage];
iconImageView.frame = CGRectMake(0 + padding, 0, 16, 16);
textField.leftView = iconImageView;

请注意,我对向文本字段的文本添加填充不感兴趣,例如 Set padding for UITextField with UITextBorderStyleNone

最佳答案

一个更简单的解决方案,它利用了 contentMode:

    arrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"down_arrow"]];
arrow.frame = CGRectMake(0.0, 0.0, arrow.image.size.width+10.0, arrow.image.size.height);
arrow.contentMode = UIViewContentModeCenter;

textField.rightView = arrow;
textField.rightViewMode = UITextFieldViewModeAlways;

在 Swift 3 中,

    let arrow = UIImageView(image: UIImage(named: "arrowDrop"))
if let size = arrow.image?.size {
arrow.frame = CGRect(x: 0.0, y: 0.0, width: size.width + 10.0, height: size.height)
}
arrow.contentMode = UIViewContentMode.center
self.textField.rightView = arrow
self.textField.rightViewMode = UITextFieldViewMode.always

关于ios - iOS7 上的 UITextfield leftView/rightView 填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19371018/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com