UIImage, check if contain image

后端 未结 4 923
别那么骄傲
别那么骄傲 2020-12-24 01:51

If I instantiate a UIImage like this :

UIImage *image = [[UIImage alloc] init];

The object is created but it doesn\'t contain any image.

4条回答
  •  心在旅途
    2020-12-24 02:34

    Check for cgImage or ciImage, in Swift 3

    public extension UIImage {
    
      public var hasContent: Bool {
        return cgImage != nil || ciImage != nil
      }
    }
    

    CGImage: If the UIImage object was initialized using a CIImage object, the value of the property is NULL.

    CIImage: If the UIImage object was initialized using a CGImageRef, the value of the property is nil.

提交回复
热议问题