gpt4 book ai didi

iphone - iOS:在 UIView 中绘制阴影

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

我发现了一些很棒的代码,它们是 UIView 的子类,它用阴影绘制该 View 。然后我可以在任何想要放置阴影的地方使用该 View :

-(void) layoutSubviews {
CGFloat coloredBoxMargin = 40;
CGFloat coloredBoxHeight = self.frame.size.height;
_coloredBoxRect = CGRectMake(coloredBoxMargin, 0, 40, coloredBoxHeight);
}

-(void) drawRect:(CGRect)rect {

CGColorRef lightColor = [UIColor colorWithRed:105.0f/255.0f green:179.0f/255.0f blue:216.0f/255.0f alpha:0.8].CGColor;
CGColorRef shadowColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.4].CGColor;

CGContextRef context = UIGraphicsGetCurrentContext();
// Draw shadow
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, lightColor);
CGContextSetShadowWithColor(context, CGSizeMake(-13, 0), 10, shadowColor);

CGContextFillRect(context, _coloredBoxRect);
CGContextRestoreGState(context);
}

使用以下内容创建:

UIViewWithShadowRight* verticalLineView2 = [[[UIViewWithShadowRight alloc] initWithFrame:CGRectMake(60, 0, 40 , self.view.frame.size.height)] autorelease];
[verticalLineView2 setBackgroundColor:[UIColor clearColor]];
[verticalLineView2 setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[verticalLineView2 setClipsToBounds:NO];
[self.view addSubview:verticalLineView2];
[self.view bringSubviewToFront:verticalLineView2];

问题是,阴影是从右向左绘制的,如何反转它并从左向右绘制?

最佳答案

13设为正数而不是负数。这是绘制阴影的 x 偏移量,负值位于原始绘图的左侧,正值位于原始绘图的右侧。

关于iphone - iOS:在 UIView 中绘制阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8045985/

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