Array element cannot be bridged to Objective-C

后端 未结 5 1456
庸人自扰
庸人自扰 2020-12-01 14:13

I have this code that creates a view and applies a gradient to it.

import UIKit
import QuartzCore


let rect : CGRect = CGRectMake(0,0,320,100)

var vista :          


        
5条回答
  •  悲&欢浪女
    2020-12-01 14:16

    I found that I could fix the problem by explicitly using CGColorRef rather than CGColor for my colours, e.g.:

        var bottomColour:CGColorRef = UIColor.redColor().CGColor
        var topColour:CGColorRef = UIColor(red: 255.0/255.0, green: 123.0/255.0, blue: 37.0/255.0, alpha: 1.0).CGColor
    
        gradientLayer.colors = [bottomColour, topColour]
    

    ...worked fine, without any NSArray or AnyObject casting. If I take out the explicit CGColorRef in the type declarations for the colours, I get the "array element cannot be bridged to Objective-C" error.

提交回复
热议问题