Post

Replies

Boosts

Views

Activity

Svg image file scaled losing it width and height ratio.
I tried set button's image with svg assets file, it can be recognized it xcode but it cannot maintain its width and height ratio when I put 3 buttons in stackview horizontally with fill equally distribution and height constraint. It can figure out the width of the image in the button with png file before, but it scaled to the whole width space of the button when I tried svg image file. I want to use svg file to scale to given height constraint and figure out it own width. Could anyone tell me how to make this happen?
1
0
3.2k
Jun ’21
Can not ForEach Int Array in Dictionary
I cannot ForEach the value of dictionary which is an Int array. Here is my code: @State private var notedNumbers: [Int:[Int]] = [:] ForEach(Array(notedNumbers.keys.enumerated()), id: \.element) { _, key in let row = key / 9 let col = key % 9 ForEach(notedNumbers[key].indices, id: \.self) { i in // Cannot ForEach the Int Array here, compiler cannot type check the expression. } }
3
0
1.2k
Jun ’21
Text expression in two nested ForEach loop cannot compile
I want to put text based on the value of 2d array and the index of 2d array. So I tried with ForEach to access array's indices and position text by the current index in 2d array. Here is the code: var body: some View { GeometryReader { geometry in let w = geometry.size.width let h = geometry.size.height ForEach(originNumbers.indices, id: \.self) { i in ForEach(originNumbers[i].indices, id: \.self) { j in if originNumbers[i][j] != 0 { Text("\(originNumbers[i][j])").font(.system(size: 500)).minimumScaleFactor(0.001) .lineLimit(1) .frame(height: h / 9.0, alignment: .center) .position(x: j * w / 9.0 + w / 18.0, y: i * h / 9.0 + h / 18.0) } } } // if originNumbers[2][2] != 0 { // Text("\(originNumbers[0][0])").font(.system(size: 500)).minimumScaleFactor(0.001) // .lineLimit(1) // .frame(width: w / 9.0, height: h / 9.0, alignment: .center) // .position(x: 2 * w / 9.0 + w / 18.0, y: 2 * h / 9.0 + h / 18.0) // } } } The compiler complain about it cannot type check the expression in reasonable time. I try to uncomment the comment part and comment the uncomment part in the code block, it works. But when put the same code in two nested ForEach loop, it will not work.
1
0
707
May ’21