【发布时间】:2011-11-08 04:31:57
【问题描述】:
我发现了一些很棒的代码,它是UIView 的子类,它用阴影绘制了该视图。然后我可以在任何我想放置阴影的地方使用该视图:
-(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];
问题是,阴影是从右向左绘制的,我该如何反转它并从左向右绘制?
【问题讨论】:
标签: iphone objective-c ios uiview core-graphics