iOS简单实现图片模糊渐变效果

文章说明:本文可以其实只是个人对知识的记录,为了自己以后找起来方便

例子参考链接 http://code4app.com/ios/EssentialImager/527cb3596803fa4e50000000

实现原理:其实就是用一张黑白的渐变图片作为底图

效果图片:

具体代码:

    CALayer *imageMaskLayer2 = [CALayerlayer];

    UIImage *pattern2 = [UIImage imageNamed:@"pattern.png"];

    imageMaskLayer2.contents = (__bridgeid)pattern2.CGImage;

    imageMaskLayer2.frame =CGRectMake(0,0, pattern2.size.width, pattern2.size.height);

    

    UIView *clippingViewForLayerImageMask2 = [[UIViewalloc] initWithFrame:CGRectMake(160,310, 120, 120)];

    clippingViewForLayerImageMask2.layer.mask = imageMaskLayer2;

    clippingViewForLayerImageMask2.clipsToBounds =YES;

    [self.viewaddSubview:clippingViewForLayerImageMask2];

    

    UIImageView *imageMaskedRadialGradientImage = [[UIImageViewalloc] initWithFrame:CGRectMake(0,0, 120, 120)];

    imageMaskedRadialGradientImage.backgroundColor = [UIColorlightGrayColor];

    [clippingViewForLayerImageMask2addSubview:imageMaskedRadialGradientImage];

    

    //aa.png 资源包的测试图片

    imageMaskedRadialGradientImage.image = [UIImageimageNamed:@"aa.png"];

    imageMaskedRadialGradientImage.frame =CGRectMake(0,0, pattern2.size.width, pattern2.size.height);

    imageMaskedRadialGradientImage.center =CGPointMake(imageMaskedRadialGradientImage.superview.frame.size.width/2,imageMaskedRadialGradientImage.superview.frame.size.height/2);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值