【问题标题】:addSubview in a textField shows CGContextSetFillColorWithColor: invalid context 0x0textField 中的 addSubview 显示 CGContextSetFillColorWithColor: invalid context 0x0
【发布时间】:2018-03-18 07:46:15
【问题描述】:

您好,我尝试在名为 typeDeProbleme 的文本字段中添加 UIImageView。一切正常,没有显示错误,除非我尝试单击 typeDeProbleme,XCode 在目标输出中给了我这个:

[未知进程名称] CGContextSetFillColorWithColor: 无效上下文 0x0。如果要查看回溯,请设置 CG_CONTEXT_SHOW_BACKTRACE 环境变量。

let imageView = UIImageView()
let image = UIImage(named: "arrow")
imageView.image = image
imageView.frame = CGRect(x: 0, y: 0, width: 25, height: 15)
imageView.contentMode = .scaleAspectFit
typeDeProbleme.rightViewMode = UITextFieldViewMode.always
typeDeProbleme.rightView = imageView
typeDeProbleme.addSubview(imageView)

我已经尝试从 CGContextSetFillColorWithColor: invalid context 0x0 中理解,但我不能,因为它在 Objective-C 中。因此,我只想知道,我在这里错过了什么吗?

【问题讨论】:

    标签: ios swift xcode uiimageview


    【解决方案1】:

    试试这个,我想这会对你有所帮助...

        let rightView = UIView(frame: CGRect(x: 0, y: 0, width: 25, height: 15))
        let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 25, height: 15))
        imageView.image = UIImage(named: "arrow")
        rightView.addSubview(imageView)
    
        typeDeProbleme.rightView = rightView
        typeDeProbleme.rightViewMode = .always
    

    【讨论】:

    • 很遗憾没有...感谢您的帮助...如果您知道问题出在哪里,请给我解释一下吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多