这类似于UITextField rightView 重叠右对齐文本, 但我很难理解如何解决这个问题:
当我设置 borderStyle = .none 时,重叠发生在 ios 13.1 如果边框存在,则文本不会与图像重叠。
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
}
Run Code Online (Sandbox Code Playgroud)
如果我摆脱
if #available(iOS 13, *) {
self.rightView = rightImageView
Run Code Online (Sandbox Code Playgroud)
从而进入 ios12 路径,图像以 UITextField 为中心,文本完全消失:

我可以做些什么来修复我的代码,或者如果我的代码看起来没问题,我是否需要向苹果提交错误?
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.
Starting in iOS 13, the implementation of leftViewRect(forBounds:) and rightViewRect(forBounds:) now ask the view for its systemLayoutSizeFitting(_:).
To achieve the previous behavior when linking against and running on iOS 13, add explicit sizing constraints on the view, wrap it in a plain UIView, or subclass the view and implement systemLayoutSizeFitting(_:)
Method override in textField class
override func rightViewRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(x: bounds.width - 50, y: 0, width: 30 , height: bounds.height)
}
Run Code Online (Sandbox Code Playgroud)
Reference link - https://howtotechglitz.com/apple-has-just-released-ios-13-developer-beta-5-for-iphone-ios-iphone-gadget-hacks/
Hope it's helps to you.
| 归档时间: |
|
| 查看次数: |
2052 次 |
| 最近记录: |