gpt4 book ai didi

ios - 文本字段中的 addSubview 显示 CGContextSetFillColorWithColor : invalid context 0x0

转载 作者:行者123 更新时间:2023-11-28 08:01:21 24 4
gpt4 key购买 nike

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

[Unknown process name] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

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 中。因此,我只想知道,我是否遗漏了什么?

最佳答案

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

    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

关于ios - 文本字段中的 addSubview 显示 CGContextSetFillColorWithColor : invalid context 0x0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46606817/

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