2015-03-02 45 views
1

我有三個按鈕,都有不同的方向。 我必須用紅線連接它們。如何連接按鈕框架?

就像抽動Tec的的Toc如果遊戲結束不是如何將它們與線路連接:

如何在它們之間設置線?

+0

有很多方法可以這樣做。 QuartzCore是一種方法。 – Raptor 2015-03-02 06:35:40

+0

你能告訴我如何用QuartzCore做到這一點嗎?或者如果可能,舉一些例子。 – Gabber 2015-03-02 06:40:36

+0

強烈建議您先嚐試一下。至少向我們展示一些你的嘗試。 – Raptor 2015-03-02 07:02:50

回答

0

這是描畫線單程:

在這裏你需要繼承的UIView,然後使用CoreGraphics中的drawRect方法調用:如下

- (void)drawRect:(CGRect)rect 
{ 

    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetLineWidth(context, 4.0); 
    CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
    CGContextMoveToPoint(context, 25, 25); 
    CGContextAddLineToPoint(context, 75, 75); 
    CGContextStrokePath(context); 

} 

另一種方法是使用UIBezierPath:

UIBezierPath *path = [UIBezierPath bezierPath]; 
[path moveToPoint:CGPointMake(10.0, 10.0)]; 
[path addLineToPoint:CGPointMake(100.0, 100.0)]; 

CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 
shapeLayer.path = [path CGPath]; 
shapeLayer.strokeColor = [[UIColor blueColor] CGColor]; 
shapeLayer.lineWidth = 3.0; 
shapeLayer.fillColor = [[UIColor clearColor] CGColor]; 

[self.view.layer addSublayer:shapeLayer]; 
+0

更好地提供以上的更多信息。通過重寫'UIView'的'drawRect'函數,你可以在上下文中繪製簡單的模式(比如一行)。 – Raptor 2015-03-02 06:42:19

0

或者您可以使用此代碼。

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 200, self.view.bounds.size.width, 1)]; 

lineView.backgroundColor = [UIColor blackColor]; 

[self.view addSubview:lineView];