.testFrame()

用來測試一個 view 的 bound ( child's actual size) 與 frame (proposed size from parent) 之間的關係。

注意:這是一個 🅿️ ViewModifier

/*
 * Thinking is SwiftUI
 * - Ch. 4, Layout
 *
 * ⭐️ Required: 📦 FrameBehavior
 */

import SwiftUI

// 🌀View + .testFrame()
extension View {
    /// ## Examples: 
    /// - `view.testFrame()`
    /// - `view.testFrame(frameColor: .yellow)`
    /// - Parameters:
    ///   - boundColor: bound's border color
    ///   - frameColor: frame's border color
    ///   - maxWidth  : frame's max width
    ///   - maxHeight : frame's max height
    ///   - showGrids : if `true`, show grid lines in the background
    public func testFrame(
        boundColor: Color     = .blue,
        frameColor: Color     = .pink,
        maxWidth  : CGFloat   = 400, 
        maxHeight : CGFloat   = 400, 
        showGrids : Bool      = true
    ) -> some View {
        self.modifier(
            FrameBehavior(                // 📦 FrameBehavior
                boundColor: boundColor, 
                frameColor: frameColor, 
                maxWidth  : maxWidth, 
                maxHeight : maxHeight, 
                showGrids : showGrids
            )
        )
    }
}

Last updated