反转 CGRect - Swift
Reversing CGRect - Swift
我怎样才能恢复我的 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))
...
}
@Nordeast 解决了:
for x in (0..<ansWithoutSpaces.count).reversed() {
...
}
for arrayIndex in stride(from: ansWithoutSpaces.count - 1, through: 0, by: -1) {
x = ansWithoutSpaces[arrayIndex]
}
我怎样才能恢复我的 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))
...
}
@Nordeast 解决了:
for x in (0..<ansWithoutSpaces.count).reversed() {
...
}
for arrayIndex in stride(from: ansWithoutSpaces.count - 1, through: 0, by: -1) {
x = ansWithoutSpaces[arrayIndex]
}