Post

Replies

Boosts

Views

Activity

text alignment in SwiftUI
I would like to center align the text inside a TextField. I just couldn't find a way to do it. I know in UIKit you could domytext.textAlignment = .rightCould anyone post the equivenant of this in SwiftUI please?
4
2
19k
Mar ’22
scale or nativescale? which one to use when you want to round to the nearest pixel?
I am trying to draw a grid inside a SwiftUI view. I am using Path with 'move(to' 'addLine(to' etc. I am trying to adjust the position of the lines to the nearest pixel to avoid anti-aliasing. At first I had a plan line this.         let positionX: CGFloat = start.x         let scaleFactor = UIScreen.main.scale         let posInPixels = positionX * scaleFactor         let posRoundedToNearestHalfPixel = Int(round(posInPixels * 2))                 let adjustByHalfpixel: Bool         if posRoundedToNearestHalfPixel.isMultiple(of: 2) {             /*that means we have a whole number of pixels, which means we are between pixels so add half a pixel*/             adjustByHalfpixel = true         } else {             /*we have a postion that is already on a pixel so no need to adjust*/             adjustByHalfpixel = false         }         let finalValueInWholePixels = CGFloat(posRoundedToNearestHalfPixel + (adjustByHalfpixel ? 1 : 0))/CGFloat(2)         let finalAdjjustedValueInPoints = finalValueInWholePixels / scaleFactor What I am not sure about is the scale factor Should I use UIScreen.main.scale or UIScreen.main.nativescale ? It is not clear from the documentation what the difference is between those two?
0
0
927
Dec ’20