最简单,最有效的方式来遮蔽UIImageview的角落

时间:2013-01-30 04:03:28

标签: ios xcode animation uiimageview

我的应用程序有大量的图像适用于世界各地的不同城市,问题是,这些图像中的一些与右下角的白色标签效果不太好,我想知道是否有某种方式可能会模糊或遮挡角落,只有那个角落,使所有图像看起来都很好看。 示例:(是的,我知道标签与城市不匹配,我尚未导入所有城市。)

那个人可能看起来很好。

enter image description here

但是这个可以使用一些阴影。 无论如何,让我使UIImageView在右下角有一些模糊/遮蔽阴影效果,使所有图像看起来都不错,而不必拍摄数百张单张照片? 非常感谢你们。

2 个答案:

答案 0 :(得分:1)

您可以使用CILinearGradient仅在一个角落获得渐晕效果:

enter image description here

- (CIImage*) processPhoto:(CIImage*)image {
    CGFloat width = [image extent].size.width;
    CGFloat height = [image extent].size.height;

    CIFilter* gradient = [CIFilter filterWithName:CILinearGradient];

    [gradient setValue:
        [CIVector vectorWithX:width*0.75 Y:height*0.5]
                forKey:@"inputPoint0"];

    [gradient setValue:
        [CIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0]
                forKey:@"inputColor0"];

    [gradient setValue:
        [CIVector vectorWithX:width*0.85 Y:0]
                forKey:@"inputPoint1"];

    [gradient setValue:
        [CIColor colorWithRed:0 green:0 blue:0 alpha:0.7]
                forKey:@"inputColor1"];

    CIImage* croppedImage =
        [gradient.outputImage imageByCroppingToRect:[image extent]];

    CIFilter* composite = [CIFilter filterWithName:CIHardLightBlendMode];
    [composite setValue:croppedImage forKey:kCIInputImageKey];
    [composite setValue:image forKey:kCIInputBackgroundImageKey];
    return composite.outputImage;
}

您可能需要稍微调整端点和渐变以获得最佳结果。

或者,如果你想要一个方形的外观,你可以在文本和图像之间用黑色背景和~0.4不透明度粘贴UIView:

enter image description here

设计方面,我认为这是一种更好的方法,但代码并不那么有趣!

答案 1 :(得分:-1)

您可以更改图像的CALayer属性..这是非常有效和强大的 试试这个:

UIView * view = [[UIView alloc] initWithFrame:frame];

view.layer.shadowColor = [[UIColor COLOR] CGColor];

view.layer.shadowRadius = 5.0;

view.layer.cornerRadius = 5.0;

相关问题