我如何逆转我的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))
...
}发布于 2020-02-17 18:17:21
@Nordeast解决了这个问题:
for x in (0..<ansWithoutSpaces.count).reversed() {
...
}发布于 2020-02-17 18:29:03
for arrayIndex in stride(from: ansWithoutSpaces.count - 1, through: 0, by: -1) {
x = ansWithoutSpaces[arrayIndex]
}https://stackoverflow.com/questions/50707928
复制相似问题