iOS Swift - UIImageView无法设置ContentMode

时间:2015-05-13 22:40:43

标签: ios swift uiimageview cifilter contentmode

我使用CIFilter为图像添加过滤器。过滤图像后生成的图像大小为CGRectMake(10, 10, 70, 70)。我无法将结果图像内容模式设置为ScaleAspectFill。这是代码:

    filter2image.frame = CGRectMake(90, 10, 70, 70)
    let filter2data = CIFilter(name: "CIPhotoEffectChrome")
    filter2data.setValue(CIImage(image: imageView.image), forKey: kCIInputImageKey)
    self.filter2image.image = UIImage(CIImage: filter2data.outputImage)
    filter2image.contentMode = UIViewContentMode.ScaleAspectFill

1 个答案:

答案 0 :(得分:0)

设置contentMode后尝试更改框架。像这样:

let filter2data = CIFilter(name: "CIPhotoEffectChrome")
filter2data.setValue(CIImage(image: imageView.image), forKey: kCIInputImageKey)
self.filter2image.image = UIImage(CIImage: filter2data.outputImage)
filter2image.contentMode = UIViewContentMode.ScaleAspectFill
filter2image.frame = CGRectMake(90, 10, 70, 70)