視圖變成了一個黑色的矩形,下面是畫視圖的代碼:
- (void)drawRect:(CGRect)rect
{
//// General Declarations
CGContextRef context = UIGraphicsGetCurrentContext();
//// Color Declarations
UIColor* color3 = [UIColor colorWithRed: 0.102 green: 0.737 blue: 0.612 alpha: 1];
UIColor* buttonStrokeColor = [UIColor colorWithRed: 0.925 green: 0.941 blue: 0.945 alpha: 0.004];
//// Image Declarations
UIImage* image = [UIImage imageNamed: @"image"];
UIColor* imagePattern = [UIColor colorWithPatternImage: image];
//// Group 2
{
//// AddButton Drawing
UIBezierPath* addButtonPath = [UIBezierPath bezierPathWithRect: CGRectMake(280.0, 3.0, 30, 30)];
[color3 setFill];
[addButtonPath fill];
[buttonStrokeColor setStroke];
addButtonPath.lineWidth = 1;
[addButtonPath stroke];
//// Group
{
//// Rectangle Drawing
UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(280.0, 3.0, 30.0, 30.0)];
CGContextSaveGState(context);
CGContextSetPatternPhase(context, CGSizeMake(86, 33));
[imagePattern setFill];
[rectanglePath fill];
CGContextRestoreGState(context);
[buttonStrokeColor setStroke];
rectanglePath.lineWidth = 1;
[rectanglePath stroke];
}
}
不知道為什麼變成黑盒子了?
可能是你繪制時超出了視圖本身的邊框。繪制時不能根據視圖的框架畫,要根據視圖的邊界畫。
更新貝塞爾曲線的起始應該是0.0。
並且在運行時要根據視圖的尺寸進行編碼。