.frame()
// 2022.02.14 + (method) .frame(cgfloat)
import SwiftUI
// ๐View+frame()
extension View {
/// Examples:
/// ```
/// view.frame(size)
/// view.frame(nil)
/// ```
public func frame(_ size: CGSize?, alignment: Alignment = .center) -> some View {
frame(width: size?.width, height: size?.height, alignment: alignment)
}
/// `view.frame(w, h)`
public func frame(_ width: CGFloat, _ height: CGFloat) -> some View {
frame(width: width, height: height)
}
/// `view.frame(cgfloat)`
public func frame(_ size: CGFloat) -> some View {
frame(width: size, height: size)
}
}
SwiftUI โฉ View โฉ Layout Modifiers โฉ .frame(width:height:alignment:)
Core Graphics โฉ
convenience extensions for Frame.
uses CGSize of Core Graphicsto set frame.
History
2020.10.12๏ผโ๏ธ .frame(_ size:CGSize) ๆน็บ CGSize?
2022.02.07: / ็ฐกๅ .frame(size) ่ชๆณใ
import SwiftUI
// ๐View + .frame()
extension View {
/// Example: `view.frame(size)`
public func frame(_ size: CGSize) -> some View {
frame(width: size.width, height: size.height)
}
/// Example: `view.frame(100, 200)`
public func frame(_ width: CGFloat, _ height: CGFloat) -> some View {
frame(width: width, height: height)
}
}
import SwiftUI
// ๐view.frame()
extension View {
// ๐view.frame(size)
@ViewBuilder public func frame(_ size: CGSize?) -> some View {
if size != nil {
frame(width: size!.width, height: size!.height)
} else { self }
}
// ๐view.frame(w, h)
public func frame(_ width: CGFloat, _ height: CGFloat) -> some View {
frame(width: width, height: height)
}
}
Last updated