简体   繁体   English

如何使用Xcode在操场上画圆

[英]How to Draw Circles in Playground with Xcode

I'm working on a school project using Xcode and for part of it, I need to draw a circle on Xcode using Swift. 我正在使用Xcode进行学校项目,其中一部分,我需要使用Swift在Xcode上画一个圆。 How do I do that? 我怎么做?

The first thing you need to do is decide how large of a circle you want – this will determine the parameters you set. 您需要做的第一件事是确定所需的圆数-这将确定您设置的参数。 The first thing you do is make a constant named whatever you want and make it a square. 您要做的第一件事是使一个常量命名为您想要的任何东西,并使其成为正方形。 Then, you can use variableName.layer.cornerRadius to make your circle. 然后,您可以使用variableName.layer.cornerRadius制作圆圈。 You have to use half of what you made the square as it is the radius of the circle. 您必须使用制作正方形的一半,因为它是圆的半径。

Here's an example of a circle with a 10 radius: 这是一个半径为10的圆的示例:

let circle = UIView(frame: CGRect(x:0, y:0, width: 20, height: 20))

circle.backgroundColor = UIColor.blue //this is just so the circle is visible

circle.layer.cornerRadius = 10

The really important thing to remember is that the square that you originally make must have the width and height be twice the size of the radius. 要记住的真正重要的事情是,您最初制作的正方形的宽度和高度必须是半径大小的两倍。 Also, if you are having trouble seeing the circle then it might be because you didn't set a background color to it, so do something like the code above by setting the color to anything you want 另外,如果您看不到圆圈,则可能是因为您没有为其设置背景色,所以可以通过将颜色设置为所需的颜色来执行类似上面代码的操作

.

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

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