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?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi, This question is about the tutorials in this page https://developer.apple.com/tutorials/swiftui/
Are they updated with the new things, such as the app and Scene protocols, Lazy stacks etc ?
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?