我试图在我的UIView子类中绘制一些东西但是当我将它添加为子视图时它只显示一个黑色视图。我做错了吗?
- (void)drawRect:(CGRect)rect
{
//// Color Declarations
UIColor* shape5Color = [UIColor redColor];
//// Shape 5 Drawing
UIBezierPath* shape5Path = UIBezierPath.bezierPath;
[shape5Path moveToPoint: CGPointMake(54.99, 118)];
[shape5Path addLineToPoint: CGPointMake(460.01, 118)];
[shape5Path addLineToPoint: CGPointMake(460.01, 355)];
[shape5Path addLineToPoint: CGPointMake(383.75, 355)];
[shape5Path addLineToPoint: CGPointMake(363.26, 327.94)];
[shape5Path addLineToPoint: CGPointMake(433, 327.94)];
[shape5Path addLineToPoint: CGPointMake(433, 145)];
[shape5Path addLineToPoint: CGPointMake(84, 144.96)];
[shape5Path addLineToPoint: CGPointMake(84, 327.94)];
[shape5Path addLineToPoint: CGPointMake(152.62, 327.94)];
[shape5Path addLineToPoint: CGPointMake(133, 355)];
[shape5Path addLineToPoint: CGPointMake(54.99, 355)];
[shape5Path addLineToPoint: CGPointMake(54.99, 118)];
[shape5Path closePath];
[shape5Path moveToPoint: CGPointMake(257, 223.5)];
[shape5Path addLineToPoint: CGPointMake(394.27, 404)];
[shape5Path addLineToPoint: CGPointMake(119.73, 404)];
[shape5Path addLineToPoint: CGPointMake(257, 223.5)];
[shape5Path closePath];
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGFloat sx = 179.0 / shape5Path.bounds.size.width;
CGFloat sy = 179.0 / shape5Path.bounds.size.height;
CGContextScaleCTM(currentContext, sx, sy);
[shape5Color setFill];
[shape5Path fill];
}
我尝试将视图的背景设置为clearColor,但这并不起作用。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
}
return self;
}