我有一个自定义的UIView,它是一个带圆角矩形的阴影和一个小边框。CGContextSetShadowWithColor在设备上没有显示
- (void) drawRect:(CGRect)rect {
//// General Declarations
CGContextRef context = UIGraphicsGetCurrentContext();
//// Shadow Declarations
CGColorRef shadow = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.3].CGColor;
CGSize shadowOffset = CGSizeMake(0, 1);
CGFloat shadowBlurRadius = 2;
//// Abstracted Graphic Attributes
CGRect roundedRectangleFrame = CGRectMake(2, 0, rect.size.width - 4, rect.size.height - 2);
//// Rounded Rectangle Drawing
UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: roundedRectangleFrame cornerRadius: 2];
CGContextSaveGState(context);
CGContextSetShadowWithColor(context, shadowOffset, shadowBlurRadius, shadow);
[[UIColor whiteColor] setFill];
[roundedRectanglePath fill];
CGContextRestoreGState(context);
[[UIColor colorWithRed:200.0/255.0 green:200.0/255.0 blue:200.0/255.0 alpha:0.3] setStroke];
roundedRectanglePath.lineWidth = 0.5;
[roundedRectanglePath stroke];
}
我的问题是,在模拟器中一切都完美呈现,但是当我在设备上运行的代码(我用的iPod touch 4代)只呈现圆角矩形和边框,但没有阴影。有任何想法吗?
您是否尝试过更大的阴影? – Larme 2013-02-13 16:18:11
是的,我尝试过,无论我做得有多大,它都会显示在设备上,甚至尝试使用红色。 – FrankWest 2013-02-13 16:22:46
你是否在超越界限?即被剪切的影子? – 2013-02-13 16:26:33