보인다. 가지고있는 이미지를 사용할 수 있지만 흰색보기를 가리고 그 뒤에 파란색보기를 배치하십시오. 또는 투명성을 취소하여 사용중인 이미지 애셋을 조정할 수 있습니다. 또는 코드에서 CoreImage
을 사용하면됩니다. 예를 들면 :
func invertMask(_ image: UIImage) -> UIImage?
{
guard let inputMaskImage = CIImage(image: image),
let backgroundImageFilter = CIFilter(name: "CIConstantColorGenerator", withInputParameters: [kCIInputColorKey: CIColor.black]),
let inputColorFilter = CIFilter(name: "CIConstantColorGenerator", withInputParameters: [kCIInputColorKey: CIColor.clear]),
let inputImage = inputColorFilter.outputImage,
let backgroundImage = backgroundImageFilter.outputImage,
let filter = CIFilter(name: "CIBlendWithAlphaMask", withInputParameters: [kCIInputImageKey: inputImage, kCIInputBackgroundImageKey: backgroundImage, kCIInputMaskImageKey: inputMaskImage]),
let filterOutput = filter.outputImage,
let outputImage = CIContext().createCGImage(filterOutput, from: inputMaskImage.extent) else { return nil }
let finalOutputImage = UIImage(cgImage: outputImage)
return finalOutputImage
}
[의 drawRect에서 아이폰 OS 반전 마스크]의 사용 가능한 복제 (https://stackoverflow.com/questions/14411765/ios-invert-mask-in-drawrect) – the4kman