【发布时间】:2011-04-25 05:39:34
【问题描述】:
我从 UIView 创建了一个类 newView 并旨在绘制一个四边形。四边形的 4 个角(ClipPointA、ClipPointB、ClipPointC、ClipPointD)应该从 ViewController 读取值。
newView.h:
@interface newView : UIView {
CGPoint ClipPointA, ClipPointB, ClipPointC, ClipPointD;
}
@end
newView.m:
@implementation newView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
}
return self;
}
- (void)drawRect:(CGRect)rect {
// Drawing code.
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 0.0, 1.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, ClipPointA.x, ClipPointA.y); //start point
CGContextAddLineToPoint(context, ClipPointB.x, ClipPointB.y);
CGContextAddLineToPoint(context, ClipPointD.x, ClipPointD.y);
CGContextAddLineToPoint(context, ClipPointC.x, ClipPointC.y); // end path
CGContextClosePath(context); // close path
CGContextSetLineWidth(context, 2.0);
CGContextStrokePath(context);
}
- (void)dealloc {
[super dealloc];
}
@end
我在 ViewController 中创建了 newView 的实例。 如何编写下一部分代码让 4 个 CGPoints 从 ViewController 读取值?
谢谢。
【问题讨论】:
标签: iphone drawrect viewcontroller