UIColor and CIColor how do they compare and what is the purpose of having two of them?

前端 未结 4 1221
醉梦人生
醉梦人生 2021-01-23 02:35

Recently I encountered some code where trying to get the CIColor property of a UIColor fails. The UIColor was initialized as a simple [UIColor blackColor] and trying to get the

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-23 02:48

    The documentation for the CIColor property on UIImage says:

    This property throws an exception if the color object was not initialized with a Core Image color.

    So if you want to access a UIColor's CIColor, it needs to have been created from a CIColor in the first place.

    On the other hand, you can make a new CIColor from any UIColor using the initWithColor: initializer:

    CIColor *color = [[CIColor alloc] initWithColor:UIColor.blackColor];
    

提交回复
热议问题