您的位置:首页 > 其它

绘制带箭头的直线

2011-08-14 23:10 218 查看
从vc移植到objective-c.感觉不错.分享之..

-(void)drawInContext:(CGContextRef)context{

CGContextSetRGBStrokeColor(context,1.0, 0.0,0.0, 1.0);

CGPoint m_One = CGPointMake(40.0,30.0);

CGPoint m_Two = CGPointMake(280.0,130.0);

double slopy , cosy , siny;

double Par =20.0; //length of Arrow (>)

slopy = atan2( ( m_One.y - m_Two.y ),

( m_One.x - m_Two.x ) );

cosy = cos( slopy );

siny = sin( slopy );//need math.h for these functions

CGContextMoveToPoint(context, m_Two.x, m_Two.y);

CGContextAddLineToPoint( context,m_Two.x + ( Par * cosy - ( Par /2.0 * siny ) ),

m_Two.y + ( Par * siny + ( Par /2.0 * cosy ) ) );

CGContextMoveToPoint( context,m_Two.x + ( Par * cosy + Par /2.0 * siny ),

m_Two.y - ( Par /2.0 * cosy - Par * siny ) );

CGContextAddLineToPoint(context, m_Two.x, m_Two.y);

CGContextSetLineWidth(context,2.0);

CGContextStrokePath(context);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: