我有一個自定義的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