In SwiftUI, what is the unit for the numbers in qualifications like frame(...)?

Viewed 318

For example:

 Text("Hello")
    .frame(width: 100, height: 60)
    .font(Font.custom("Times New", size: 36.0))

What are the units of the 100 and 60? If they mean 100 and 60 points, how is that device independent? If not points, what are they?

I'm trying to learn how to place an item (like a Text or a Button) at a fractional position within the view. For example how to center an item at 40% of the view's height down from the top. My first thought was that they might be fractions of the containing view but that appears to be wrong.

1 Answers

In points, Apple mentioned this in many places of auto-generated SwiftUI API module doc, like in below snapshot of .frame modifier descritions (see, ellipse will be 200x100 points.). There are the similar for .offset and .position.

/// For example, the first ellipse in the following code is laid out in a
/// fixed 200 by 100 frame. Since a shape always occupies the space offered
/// to it, the first ellipse will be 200x100 points. The second ellipse is
/// laid out in a frame with only a fixed height, so it occupies that
/// height, and whatever width is offered to its parent.
///
///     VStack {
///         Ellipse()
///         .fill(Color.purple)
///         .frame(width: 200, height: 100),
///         Ellipse()
///         .fill(Color.blue)
///         .frame(height: 100)
///     }

Actually everything coordinate space related is the same as in UIKit.

Related