Ios 如何绘制高斯模糊效果?

Ios 如何绘制高斯模糊效果?,ios,objective-c,xcode,gaussianblur,Ios,Objective C,Xcode,Gaussianblur,我需要使用Objective C在UIView上绘制模糊效果 这是我的设计 下面的屏幕截图是使用上述代码的当前输出 我已经试过上面的代码了,但我没有得到确切的模糊效果 请建议我画这个图案 我已经更新了下面的代码 - (void)drawRect:(CGRect)rect { [super drawRect: rect]; //i doubt we need a super drarRect here… [self drawMarker: self.markerView f

我需要使用Objective C在UIView上绘制模糊效果

这是我的设计

下面的屏幕截图是使用上述代码的当前输出

我已经试过上面的代码了,但我没有得到确切的模糊效果 请建议我画这个图案

我已经更新了下面的代码

- (void)drawRect:(CGRect)rect {

    [super drawRect: rect]; //i doubt we need a super drarRect here…

    [self drawMarker: self.markerView fillColor: [UIColor whiteColor]];

    CGContextRef ctx = UIGraphicsGetCurrentContext();


    CGPathRef path = CGPathCreateWithRoundedRect(CGRectInset(rect,  self.frame.size.width/4,  self.frame.size.height/4), self.frame.size.width/8, self.frame.size.height/8, nil);

    CGContextSetFillColorWithColor(ctx,[UIColor slateColor].CGColor);

    CGContextSetShadowWithColor(ctx, CGSizeZero, self.frame.size.height/4,  [UIColor slateColor].CGColor);


    for ( int i = 0; i<=6; i++) {
        CGContextAddPath(ctx, path);
        CGContextFillPath(ctx);
    }

}
-(void)drawRect:(CGRect)rect{
[super-drawRect:rect];//我怀疑我们这里需要一个super-drawRect…
[自绘制标记:self.markerView fillColor:[UIColor whiteColor]];
CGContextRef ctx=UIGraphicsGetCurrentContext();
CGPathRef path=CGPathCreateWithRoundedRect(CGRectInset(rect,self.frame.size.width/4,self.frame.size.height/4),self.frame.size.width/8,self.frame.size.height/8,nil);
CGContextSetFillColorWithColor(ctx,[UIColor slateColor].CGColor);
CGContextSetShadowWithColor(ctx,CGSizeZero,self.frame.size.height/4,[UIColor slateColor].CGColor);

对于(int i=0;i请查看我用于模糊效果的以下参考:


这仅适用于高斯模糊效果。

将我先前的答案从swift转换为Objective-C,我们有这个

@implementation UICustomBackgroundButton


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    [super drawRect:rect];

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGPathRef path = CGPathCreateWithRoundedRect(CGRectInset(rect,  self.frame.size.width/4,  self.frame.size.height/4), self.frame.size.width/8, self.frame.size.height/8, nil);

    CGContextSetFillColorWithColor(ctx,[UIColor blueColor].CGColor);
    CGContextSetShadowWithColor(ctx, CGSizeZero, self.frame.size.height/4,  [UIColor blueColor].CGColor);


    for ( int i = 0; i<=6; i++) {
        CGContextAddPath(ctx, path);
        CGContextFillPath(ctx);
    }
}


@end
@实现UICustomBackgroundButton
//仅覆盖drawRect:如果执行自定义绘图。
//空实现会对动画期间的性能产生不利影响。
-(void)drawRect:(CGRect)rect{
//绘图代码
[超级drawRect:rect];
CGContextRef ctx=UIGraphicsGetCurrentContext();
CGPathRef path=CGPathCreateWithRoundedRect(CGRectInset(rect,self.frame.size.width/4,self.frame.size.height/4),self.frame.size.width/8,self.frame.size.height/8,nil);
CGContextSetFillColorWithColor(ctx,[UIColor blueColor].CGColor];
CGContextSetShadowWithColor(ctx,CGSizeZero,self.frame.size.height/4,[UIColor blueColor].CGColor);

对于(int i=0;我检查此代码可能会帮助您,让我知道我只收到崩溃提示或错误?此代码已使用2年,无论如何我可以更新它,顺便说一句,此答案在swift上#reinier melian我添加了代码,但我没有得到确切的模糊位置请检查我的问题我更新了新代码并screenshot@Nandhakumar我会查一查的让你知道
@implementation UICustomBackgroundButton


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    [super drawRect:rect];

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGPathRef path = CGPathCreateWithRoundedRect(CGRectInset(rect,  self.frame.size.width/4,  self.frame.size.height/4), self.frame.size.width/8, self.frame.size.height/8, nil);

    CGContextSetFillColorWithColor(ctx,[UIColor blueColor].CGColor);
    CGContextSetShadowWithColor(ctx, CGSizeZero, self.frame.size.height/4,  [UIColor blueColor].CGColor);


    for ( int i = 0; i<=6; i++) {
        CGContextAddPath(ctx, path);
        CGContextFillPath(ctx);
    }
}


@end