gpt4 book ai didi

ios - 如何绘制高斯模糊效果?

转载 作者:行者123 更新时间:2023-11-29 11:28:24 26 4
gpt4 key购买 nike

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

这是我的设计

enter image description here

    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle: UIBlurEffectStyleExtraLight];

UIVisualEffectView *contentView = [[UIVisualEffectView alloc] initWithEffect: blurEffect];

contentView.layer.cornerRadius = 18.0;

contentView.layer.masksToBounds = YES;

contentView.backgroundColor = [UIColor whiteColor];

contentView.userInteractionEnabled = NO;

contentView.layer.shadowRadius = 10;

contentView.layer.shadowOpacity = 0.2f;

contentView.layer.shadowColor = [UIColor whiteColor].CGColor;

contentView.layer.shadowOffset = CGSizeZero;

[contentView setFrame: annotationFrame];

[contentView setTranslatesAutoresizingMaskIntoConstraints: YES];

self.contentView = contentView;

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

enter image description here

我试过上面的代码。 , 但我没有得到确切的模糊效果请建议我画这个设计。

我更新了下面的代码

- (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);
}

}

enter image description here

我需要我的观点背后的模糊效果,请就此向我提出建议。

谢谢。

最佳答案

将我之前的回答从 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

结果 enter image description here

关于ios - 如何绘制高斯模糊效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56374687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com