ios - 横向模式下 UITextField 中间出现奇怪的黑条

标签 ios swift xcode uikit swift5

我已尝试通过 View 调试器对其进行调试,但仍无法检测到其中的原因。

TextField 有下面的自定义类,如果可能有一些隐藏的问题的话

class ChatTextField: UITextField {

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        initNib()
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        initNib()
    }

    func initNib() {

        self.attributedPlaceholder = NSAttributedString(string: "Send a message to Kael",
                                                        attributes: [NSAttributedString.Key.foregroundColor: #colorLiteral(red: 0.1879999936, green: 0.1979999989, blue: 0.2930000126, alpha: 1)])
        self.layer.borderWidth = 2
        self.layer.cornerRadius = 4.0
        self.layer.borderColor = #colorLiteral(red: 0.3059999943, green: 0.5329999924, blue: 0.5490000248, alpha: 1)

        self.addInnerShadow(onSide: .all, shadowColor: UIColor(red: 0, green: 0, blue: 0, alpha: 0.2), shadowSize: 10, cornerRadius: 15, shadowOpacity: 0.8)
    }
    let padding = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 30)

     override open func textRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: padding)
     }

     override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: padding)
     }

     override open func editingRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: padding)
     }
}

Strange bklack bar in middle of UITextField

View debugger

Storyboard UI

最佳答案

您正在从 UITextField 扩展的 initNib() 方法中调用一个方法来提供内部阴影。

您必须根据纵向和横向模式设置不同的偏移 来修改阴影方法。

尝试删除将阴影应用到文本字段的阴影方法,然后检查它是否正常工作。

关于ios - 横向模式下 UITextField 中间出现奇怪的黑条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59890899/

相关文章:

ios - 在 IB 上调整 UIImage 大小的问题

iphone - iOS Storyboard 连接松动?

swift - 如何使用 AlertView 进行搜索?

XCode 3.2 : Changing the default "Code Sense" indentation and whitespaces

ios - 具有动态键和值的 NSPredicate

facebook - 在Facebook iOS SDK中获取Facebook用户 friend 姓名列表的最有效方法是什么?

iOS SpriteKit 与屏幕边缘的碰撞不起作用

macos - 在 OSX 中设置多行标签的高度

ios - 禁用 UITextView 中的水平滚动

ios - 选择行时奇怪的 tableView 行/部分动画