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

标签 ios swift xcode uiimageview

您好,我尝试在我的文本字段中添加一个名为 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/

相关文章:

arrays - 从像素阵列问题中获取 NSImage (Swift)

swift - 如何创建跨多个操作共享的实例变量

objective-c - 使用 Interface Builder 添加的 NSImageView 为 null

C++编译失败,错误: no member named 'snprintf' in namespace 'std'

ios - 以编程方式在 FBLikeControl 上添加约束

c++ - 交付具有其他依赖项的 xcode 框架

ios - objective-c/c++中的反向位操作

ios - iOS 11 上的 MKAnnotationView setImage() 有一个动画

ios - didselectrowatindexpath 文本标签返回

ios - 如何为多个 View Controller 使用 SWRevealviewcontroller 库