【发布时间】:2019-10-11 06:42:35
【问题描述】:
这类似于UITextField rightView overlaps right align text 但我很难理解如何解决这个问题:
重叠发生在 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 和文本完全消失了:
我可以做些什么来修复我的代码,或者如果我的代码看起来没问题,我是否需要向苹果提交错误?
【问题讨论】:
-
我对 ios13 有类似的问题。在我的自定义文本文件类中覆盖
rightViewRectForBounds的 rightview 方法后,这对我有用