2011-04-25 76 views
1

我从UIView创建了一个类newView,目的是绘制一个四边形。四角锥的四个锥体(ClipPointA,ClipPointB,ClipPointC,ClipPointD)应该从ViewController读取值。如何让drawRect从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 

我创建NewView的实例中的ViewController。 如何编写代码的下一部分让4个CGPoint从ViewController读取值?

谢谢。

当你创建新的UIView也请通过点如

回答

0

:设A,B,C,D是你4点

newView *nv =[[dragman alloc]initWithFrame:self.view.frame]; 
    nv.ClipPointA=A; 
    nv.ClipPointB=B; 
     nv.ClipPointC=C; 
     nv.ClipPointD=D; 
    [nv setUserInteractionEnabled:YES]; 
    [contentView addSubview:nv]; 
    [nv release]; 
+0

@ user698212:非常感谢你。什么是拉曼? – Nauhc 2011-04-25 07:58:16

相关问题