将CGPointo转换成swift[副本]

时间:2023-02-07 02:57:20

This question already has an answer here:

这个问题已经有了答案:

I'm building a class to handle with a basic graphic. I'm a newby and I'm on a self learning project to build small apps in Swift for IOS devices, since I found the language very easy to learn.

我正在构建一个类来处理一个基本的图形。我是newby,我正在进行一个自学项目,用Swift为IOS设备构建小型应用,因为我发现这门语言非常容易学习。

I've set in my class of type UIView two constants of type CGPoint:

我在UIView类中设置了两个CGPoint类型的常量

let heigh = bounds.size.heigh
let width = bounds.size.width

These 2 variables are CGFloat, but I need them to be Int. Appreciate help to convert them to these type value.

这两个变量是CGFloat,但我需要它们是Int. Appreciate帮助将它们转换为这些类型值。

1 个解决方案

#1


3  

You should be able to convert the float value to an Integer like this:

您应该能够将浮点值转换为如下所示的整数:

let height = Int(bounds.size.height)

#1


3  

You should be able to convert the float value to an Integer like this:

您应该能够将浮点值转换为如下所示的整数:

let height = Int(bounds.size.height)