简体   繁体   English

如何在iOS中的两个UIButton之间绘制直线?

[英]How to draw straight line between two UIButtons in iOS?

I want to draw straight line between two UIButtons. 我想在两个UIButton之间绘制直线。 When we touch button 1 the line will appear in black color; 当我们触摸按钮1时,该行将显示为黑色; when we touch button 3 the line will become red; 当我们触摸按钮3时,该行将变为红色; and when we touch button 2 the line will become Green and end on Button two. 当我们触摸按钮2时,该行将变为绿色,并在按钮2上结束。 So that line will be visible connected two buttons only button 1 and button 2. 这样,连接两个按钮(仅按钮1和按钮2)即可看到该行。

Now I want when I click button 4 the new line will appear in orange color. 现在,我想单击按钮4时,新行将显示为橙色。 The previous line was end on button-2 and this will be the new line. 上一行在button-2上结束,这将是新行。 And same this will connect if I touch button 5. 如果我触摸按钮5,也可以连接。

Same just like kids play matching the quiz game. 就像孩子们玩配对测验游戏一样。

Means Tv belongs to electronics (Right), sky belong to Glass (wrong). 表示电视属于电子产品(右),天空属于玻璃(错误)。 Just like that I need to connect Button 1 and Button 2 , Button 4 and Button 5. 就像我需要连接按钮1和按钮2,按钮4和按钮5一样。

Any idea or suggestions would be highly welcome. 任何想法或建议都将受到欢迎。

一种简单的方法是在按钮周围放置一些uiimageviews,并根据每个按钮的作用,根据需要在uiimageviews中添加图像或从uiimageviews中移除图像(使用不同的彩色线条)。

You can do it with the help of images. 您可以借助图像来做到这一点。 Just write your logic for replacing, hiding and unhiding the images. 只需编写替换,隐藏和取消隐藏图像的逻辑即可。 It would be a simpler approach. 这将是一个更简单的方法。

Use this: 用这个:

-(void)drawLineWithStartPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint WithColor:(UIColor *)color
{
    UIBezierPath *aPath = [UIBezierPath bezierPath];

// Set the starting point of the shape.
[aPath moveToPoint:startpoint;

// Draw the lines.
[aPath addLineToPoint:endPoint;
[aPath closePath];
 aPath.lineWidth = 2;
  [aPath fill]; 
  [aPath stroke];

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM