gpt4 book ai didi

ios - 逆向CGRect-Swift

转载 作者:行者123 更新时间:2023-12-01 22:18:02 33 4
gpt4 key购买 nike

如何反转origin.x?我的origin.x从右边开始,我想从左边开始。例如,我应用程序中x的这些起源是从最右边开始的:

1)351.0

2)304.0

3)257.0

4)210.0

5)163.0

6)116.0

7)69.0

8)22.0

我该如何扭转这些起源,从22.0开始到351.0?

代码:

var ansWithoutSpaces = String()
ansWithoutSpaces = answersString.replacingOccurrences(of: " ", with: "")

var targetHeigt = CGFloat()
let viewWidth = self.view.frame.size.width

if viewWidth == 320 {
targetHeigt = 2.5
} else {
targetHeigt = 5
}

let yAxis : Int = Int((self.view.frame.height) * 60%)
let lenghtOfChar = ansWithoutSpaces as NSString
// char count
let width: Int = Int(view.frame.size.width) - 40
// frame width
var targetWidth: Int = (width - (lenghtOfChar.length - 1) * 5) / lenghtOfChar.length

if targetWidth > 50 {
if viewWidth == 320 {
targetWidth = 38
} else if viewWidth == 375 {
targetWidth = 45
} else {
targetWidth = 50
}
}

let totalWidth: Int = (targetWidth * lenghtOfChar.length) + ((lenghtOfChar.length - 1) * 5)

for x in 0..<ansWithoutSpaces.count {
let xAxis: Int = (width / 2) - (totalWidth / 2) + (x * targetWidth) + (x * 5) + 20
let targetLabel = UILabel(frame: CGRect(x: CGFloat(xAxis), y: CGFloat(yAxis), width: CGFloat(targetWidth), height: targetHeigt))

...
}

最佳答案

for arrayIndex in stride(from: ansWithoutSpaces.count - 1, through: 0, by: -1) {
x = ansWithoutSpaces[arrayIndex]
}

关于ios - 逆向CGRect-Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50707928/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com