# 補充資料 ## [ Building Layouts with Stack Views](https://developer.apple.com/documentation/swiftui/building-layouts-with-stack-views) * If your layout has one dominant view that defines the size of the layout, use the `overlay(_:alignment:)` or `background(_:alignment:)` view modifier on that view. * If you want the final view size to come from an aggregation of all the contained views, use a `ZStack`. ![](https://i.imgur.com/qvEFoGg.png) ## [ Making Fine Adjustments to a View’s Position](https://developer.apple.com/documentation/swiftui/making-fine-adjustments-to-a-view-s-position) the `offset(x:y:)` modifier uses the parameters of x and y to represent a relative location within the view’s coordinate space. > ZStack 沒有指定 alignment,所以 Image 會在正中間(80,80)。 `.offset(x: 40.0, y: -40.0)` 加上這個偏移的話,就會坐落在第一象限。 ![](https://i.imgur.com/KFFrSaR.png) ## [Creating custom paths with SwiftUI](https://www.hackingwithswift.com/books/ios-swiftui/creating-custom-paths-with-swiftui) |尖頭三角形|圓頭三角形| |---|---| |`.stroke(.blue, lineWidth: 10)`|`.stroke(.blue, style: StrokeStyle(lineWidth: 10, lineCap: .round, lineJoin: .round))`| |![](https://i.imgur.com/dlso8XM.png)|![](https://i.imgur.com/YqZ1LVU.png)| ## [ Laying Out a Simple View](https://developer.apple.com/documentation/swiftui/laying-out-a-simple-view) 1. The `ZStack` proposes a size to its child views, the `Circle` and `Text` views. 1. The `Circle` expands up to the size offered, while the `Text` takes just enough space for the string it contains. 1. The `ZStack` returns the size of its largest child view, in this case the `Circle`. | MessageRow的大小被HStack 決定 | 變成加了約束寬度的ZStack主宰者 | |---|---| |![](https://i.imgur.com/MYL61yu.png)|![](https://i.imgur.com/mSdlRSj.png)| |![](https://i.imgur.com/3lsNeQ7.png)|![](https://i.imgur.com/EoOi4cS.png)| ## [How to control layout priority using layoutPriority()](https://www.hackingwithswift.com/quick-start/swiftui/how-to-control-layout-priority-using-layoutpriority) All views have a layout priority of 0 by default. Raising a view’s layout priority encourages the higher priority view to shrink later. ![](https://i.imgur.com/88vSDpq.png) ![](https://i.imgur.com/WFpKxe7.png)