gpt4 book ai didi

ios - UITextField leftView 和 rightView 重叠问题 - iOS13

转载 作者:行者123 更新时间:2023-11-28 19:25:46 34 4
gpt4 key购买 nike

这类似于 UITextField rightView overlaps right align text但我很难理解如何解决这个问题:

enter image description here

重叠发生在 ios 13.1 上我设置 borderStyle = .none如果存在边框,则文本不会与图片。

    public func addRightImage(_ image: UIImage, accessibilityIdentifier: String? = nil,
size: CGSize) {
self.rightViewMode = .always
let widthImageView : CGFloat = 25

let rightImageView = UIImageView(frame: .init(x: 0, y: 0, width: widthImageView, height: self.bounds.size.height))
rightImageView.accessibilityIdentifier = accessibilityIdentifier
rightImageView.image = image
if #available(iOS 13, *) {
self.rightView = rightImageView
} else {
assert(self.rightImageView == nil)
let widthView : CGFloat = is4incher ? 30 : 50

let rightView = UIView(frame: .init(x: 0, y: 0, width: widthView, height: self.bounds.size.height))
rightView.isUserInteractionEnabled = false
self.rightView = rightView
rightView.addSubview(rightImageView)

rightView.isUserInteractionEnabled = false
self.rightView = rightView

rightImageView.anchors(centerX: rightView.centerXAnchor, centerY: rightView.centerYAnchor,
size: size)
}
rightImageView.set(color: self.textColor ?? .white)
rightImageView.contentMode = .scaleAspectFit
self.rightImageView = rightImageView
}

如果我摆脱了

    if #available(iOS 13, *) {
self.rightView = rightImageView

然后进入 ios12 路径,图像居中于UITextField 和文本完全消失了: enter image description here

我可以做些什么来修复我的代码,或者如果我的代码看起来没问题,我是否需要向 apple 提交错误?

最佳答案

Swift 5 - iOS13

Prior to iOS 13, UITextField assumed that the frames of its leftView and rightView were correctly set when assigned and would never change.

从 iOS 13 开始,leftViewRect(forBounds:)rightViewRect(forBounds:) 的实现现在向 View 询问其 systemLayoutSizeFitting(_:)

要在针对 iOS 13 链接和运行时实现之前的行为,请在 View 上添加显式大小限制,将其包装在普通 UIView 中,或者将 View 子类化并实现 systemLayoutSizeFitting(_:)


textField 类中的方法覆盖

override func rightViewRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(x: bounds.width - 50, y: 0, width: 30 , height: bounds.height)
}

引用链接- https://howtotechglitz.com/apple-has-just-released-ios-13-developer-beta-5-for-iphone-ios-iphone-gadget-hacks/

希望对你有所帮助。

关于ios - UITextField leftView 和 rightView 重叠问题 - iOS13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58335586/

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