### start(_:) Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex.html Sets the distance of the start edge (LTR=left, RTL=right) from the container's start edge in pixels. ```APIDOC ## start(_:) ### Description Set the start edge (LTR=left, RTL=right) distance from the container start edge in pixels. ### Declaration ```swift public func start(_ value: CGFloat) -> Flex ``` ``` -------------------------------- ### Install Carthage Modules for iOS Source: https://github.com/layoutbox/flexlayout/blob/master/docs_markdown/contributing.md Use this command to install the necessary Carthage modules for iOS development. Ensure you have Carthage installed and are using SSH for repository access. ```bash carthage bootstrap --use-ssh --platform iOS ``` -------------------------------- ### AlignItems.start Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/Classes/Flex/AlignItems.html Use 'start' to align items to the beginning of the container along the cross axis. ```swift case start ``` -------------------------------- ### Padding Start Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/Classes/Flex.html Sets the start padding for a FlexLayout item, which adjusts based on layout direction (LTR or RTL). ```APIDOC ## paddingStart(_:) ### Description Sets the start padding. Depends on the item `LayoutDirection`. * In LTR direction, start padding specifies the offset children should have from the container’s left edge. * In RTL direction, start padding specifies the offset children should have from the container’s right edge. ### Method Swift ### Endpoint `paddingStart(_ value: CGFloat) -> Flex` ### Parameters #### Path Parameters - **value** (CGFloat) - Required - The value for the start padding. ### Response #### Success Response (200) - **Flex** - The modified Flex instance for chaining. ### Request Example ```swift flexContainer.paddingStart(10) ``` ### Response Example ```swift // Returns the Flex instance with start padding applied ``` ``` -------------------------------- ### Setup and Layout Flexbox Container Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/index.html Initialize a flexbox container and define its structure using nested flex items. Layout the container and its children within `layoutSubviews`. ```swift fileprivate let rootFlexContainer = UIView() init() { super.init(frame: .zero) addSubview(rootFlexContainer) ... // Column container rootFlexContainer.flex.direction(.column).padding(12).define { (flex) in // Row container flex.addItem().direction(.row).define { (flex) in flex.addItem(imageView).width(100).aspectRatio(of: imageView) // Column container flex.addItem().direction(.column).paddingLeft(12).grow(1).define { (flex) in flex.addItem(segmentedControl).marginBottom(12).grow(1) flex.addItem(label) } } flex.addItem().height(1).marginTop(12).backgroundColor(.lightGray) flex.addItem(bottomLabel).marginTop(12) } } override func layoutSubviews() { super.layoutSubviews() // 1) Layout the flex container. This example use PinLayout for that purpose, but it could be done // also by setting the rootFlexContainer's frame: // rootFlexContainer.frame = CGRect(x: 0, y: topLayoutGuide, // width: frame.width, height: rootFlexContainer.height) rootFlexContainer.pin.top().left().width(100%).marginTop(topLayoutGuide) // 2) Then let the flexbox container layout itself. Here the container's height will be adjusted automatically. rootFlexContainer.flex.layout(mode: .adjustHeight) } ``` -------------------------------- ### paddingStart Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex.html Set the start padding. Depends on the item LayoutDirection: In LTR direction, start padding specifies the offset children should have from the container's left edge. In RTL direction, start padding specifies the offset children should have from the container's right edge. ```APIDOC ## paddingStart(_:) ### Description Set the start padding. Depends on the item `[LayoutDirection](../Classes/Flex/LayoutDirection.html)`: * In LTR direction, start padding specify the **offset children should have** from the container’s left edge. * IN RTL direction, start padding specify the **offset children should have** from the container’s right edge. ### Method public func paddingStart(_ value: CGFloat) -> Flex ``` -------------------------------- ### marginStart (CGFloat) Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/Classes/Flex.html Set the start margin. Depends on the item LayoutDirection: In LTR direction, start margin specifies the offset the left edge of the item should have from its closest sibling (item) or parent (container). In RTL direction, start margin specifies the offset the right edge of the item should have from its closest sibling (item) or parent (container). ```APIDOC ## marginStart(_:) ### Description Set the start margin. Depends on the item `[LayoutDirection](../Classes/Flex/LayoutDirection.html)`: * In LTR direction, start margin specify the offset the **left** edge of the item should have from from it’s closest sibling (item) or parent (container). * IN RTL direction, start margin specify the offset the **right** edge of the item should have from from it’s closest sibling (item) or parent (container). ### Method `marginStart(_ value: CGFloat) -> Flex` ``` -------------------------------- ### Integrate FlexLayout with CocoaPods Source: https://github.com/layoutbox/flexlayout/blob/master/README.md Add this line to your Podfile to include FlexLayout in your project. Then run 'pod install'. ```ruby pod 'FlexLayout' ``` -------------------------------- ### paddingHorizontal Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex.html Set the left, right, start and end paddings to the specified value. ```APIDOC ## paddingHorizontal(_:) ### Description Set the left, right, start and end paddings to the specified value. ### Method public func paddingHorizontal(_ value: CGFloat) -> Flex ``` -------------------------------- ### Setup and Layout Flexbox Containers Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/index.html Initialize a flexbox container and define its children using a closure. This code sets up nested row and column layouts with padding, margins, and growth properties. Use this for defining the structure of your UI elements. ```swift fileprivate let rootFlexContainer = UIView() init() { super.init(frame: .zero) addSubview(rootFlexContainer) ... // Column container rootFlexContainer.flex.direction(.column).padding(12).define { (flex) in // Row container flex.addItem().direction(.row).define { (flex) in flex.addItem(imageView).width(100).aspectRatio(of: imageView) // Column container flex.addItem().direction(.column).paddingLeft(12).grow(1).define { (flex) in flex.addItem(segmentedControl).marginBottom(12).grow(1) flex.addItem(label) } } flex.addItem().height(1).marginTop(12).backgroundColor(.lightGray) flex.addItem(bottomLabel).marginTop(12) } } ``` ```swift override func layoutSubviews() { super.layoutSubviews() // 1) Layout the flex container. This example use PinLayout for that purpose, but it could be done // also by setting the rootFlexContainer's frame: // rootFlexContainer.frame = CGRect(x: 0, y: topLayoutGuide, // width: frame.width, height: rootFlexContainer.height) rootFlexContainer.pin.top().left().width(100%).marginTop(topLayoutGuide) // 2) Then let the flexbox container layout itself. Here the container's height will be adjusted automatically. rootFlexContainer.flex.layout(mode: .adjustHeight) } ``` -------------------------------- ### Setup and Layout Flexbox Containers in Swift Source: https://github.com/layoutbox/flexlayout/blob/master/README.md Initialize a flexbox container and define its structure using nested column and row layouts. Layout the container within `layoutSubviews` and then let Flexbox manage the children's layout, automatically adjusting the container's height. ```swift fileprivate let rootFlexContainer = UIView() init() { super.init(frame: .zero) addSubview(rootFlexContainer) ... // Column container rootFlexContainer.flex.direction(.column).padding(12).define { (flex) in // Row container flex.addItem().direction(.row).define { (flex) in flex.addItem(imageView).width(100).aspectRatio(of: imageView) // Column container flex.addItem().direction(.column).paddingLeft(12).grow(1).define { (flex) in flex.addItem(segmentedControl).marginBottom(12).grow(1) flex.addItem(label) } } flex.addItem().height(1).marginTop(12).backgroundColor(.lightGray) flex.addItem(bottomLabel).marginTop(12) } } override func layoutSubviews() { super.layoutSubviews() // 1) Layout the flex container. This example use PinLayout for that purpose, but it could be done // also by setting the rootFlexContainer's frame: // rootFlexContainer.frame = CGRect(x: 0, y: 0, // width: frame.width, height: rootFlexContainer.height) rootFlexContainer.pin.top().left().width(100%).marginTop(topLayoutGuide) // 2) Then let the flexbox container layout itself. Here the container's height will be adjusted automatically. rootFlexContainer.flex.layout(mode: .adjustHeight) } ``` -------------------------------- ### Set Start Padding in FlexLayout Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex.html Use `paddingStart(_:)` to set padding based on the layout direction. In LTR, it affects the left edge; in RTL, it affects the right edge. This method returns a modified Flex instance. ```Swift public func paddingStart(_ value: CGFloat) -> Flex ``` -------------------------------- ### Set Flex Item Position with Offsets Source: https://github.com/layoutbox/flexlayout/blob/master/README.md Examples of positioning flex items using top, right, left, and right properties with absolute or relative positioning. Percentages can also be used for offsets. ```swift view.flex.position(.relative).top(10).right(10).width(100).height(50) view.flex.position(.absolute).top(10).right(10).width(100).height(50) view.flex.position(.absolute).left(20%).right(20%) ``` -------------------------------- ### Implement Ray Wenderlich Tutorial Screen with FlexLayout Source: https://github.com/layoutbox/flexlayout/blob/master/README.md This Swift code defines the UI structure for the Ray Wenderlich tutorial screen using FlexLayout's declarative API. It sets up various rows and sections for content like images, text, and action buttons. The layout is adjusted to fit the content height. ```swift init() { ... rootFlexContainer.flex.define { (flex) in // Image flex.addItem(episodeImageView).grow(1).backgroundColor(.gray) // Summary row flex.addItem().direction(.row).padding(padding).define { (flex) in flex.addItem(summaryPopularityLabel).grow(1) flex.addItem().direction(.row).justifyContent(.spaceBetween).grow(2).define { (flex) in flex.addItem(yearLabel) flex.addItem(ratingLabel) flex.addItem(lengthLabel) } flex.addItem().width(100).height(1).grow(1) } // Title row flex.addItem().direction(.row).padding(padding).define { (flex) in flex.addItem(episodeIdLabel) flex.addItem(episodeTitleLabel).marginLeft(20) } // Description section flex.addItem().paddingHorizontal(paddingHorizontal).define { (flex) in flex.addItem(descriptionLabel) flex.addItem(castLabel) flex.addItem(creatorsLabel) } // Action row flex.addItem().direction(.row).padding(padding).define { (flex) in flex.addItem(addActionView) flex.addItem(shareActionView) } // Tabs row flex.addItem().direction(.row).padding(padding).define { (flex) in flex.addItem(episodesTabView) flex.addItem(moreTabView) } // Shows TableView flex.addItem(showsTableView).grow(1) } } override func layoutSubviews() { super.layoutSubviews() // 1) Layout the contentView & rootFlexContainer using PinLayout contentView.pin.top().bottom().left().right() rootFlexContainer.pin.top().left().right() // 2) Let the flexbox container layout itself and adjust the height rootFlexContainer.flex.layout(mode: .adjustHeight) // 3) Adjust the scrollview contentSize contentView.contentSize = rootFlexContainer.frame.size } ``` -------------------------------- ### Implement Ray Wenderlich Tutorial Screen with FlexLayout Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/index.html This snippet demonstrates how to structure a complex view hierarchy using FlexLayout's define and addItem methods. It's useful for building intricate UIs with nested layouts. ```swift init() { ... rootFlexContainer.flex.define { (flex) in // Image flex.addItem(episodeImageView).grow(1).backgroundColor(.gray) // Summary row flex.addItem().direction(.row).padding(padding).define({ (flex) in flex.addItem(summaryPopularityLabel).grow(1) flex.addItem().direction(.row).justifyContent(.spaceBetween).grow(2).define({ (flex) in flex.addItem(yearLabel) flex.addItem(ratingLabel) flex.addItem(lengthLabel) }) flex.addItem().width(100).height(1).grow(1) }) // Title row flex.addItem().direction(.row).padding(padding).define({ (flex) in flex.addItem(episodeIdLabel) flex.addItem(episodeTitleLabel).marginLeft(20) }) // Description section flex.addItem().paddingHorizontal(paddingHorizontal).define({ (flex) in flex.addItem(descriptionLabel) flex.addItem(castLabel) flex.addItem(creatorsLabel) }) // Action row flex.addItem().direction(.row).padding(padding).define({ (flex) in flex.addItem(addActionView) flex.addItem(shareActionView) }) // Tabs row flex.addItem().direction(.row).padding(padding).define({ (flex) in flex.addItem(episodesTabView) flex.addItem(moreTabView) }) // Shows TableView flex.addItem(showsTableView).grow(1) } } override func layoutSubviews() { super.layoutSubviews() // 1) Layout the contentView & rootFlexContainer using PinLayout contentView.pin.top().bottom().left().right() rootFlexContainer.pin.top().left().right() // 2) Let the flexbox container layout itself and adjust the height rootFlexContainer.flex.layout(mode: .adjustHeight) // 3) Adjust the scrollview contentSize contentView.contentSize = rootFlexContainer.frame.size } ``` -------------------------------- ### Get Natural Content Size with intrinsicSize Source: https://context7.com/layoutbox/flexlayout/llms.txt Access the `intrinsicSize` property to get a flex item's natural size based on its own properties, independent of its parent. This is particularly useful for intrinsically-sized views like labels. ```swift let badge = UILabel() badge.text = "42 unread" badge.font = .systemFont(ofSize: 12) // Measure the badge's natural size before adding it to a layout badge.flex.padding(4, 8) let natural = badge.flex.intrinsicSize print("Badge natural size: \(natural)") // e.g. CGSize(width: 92, height: 28) ``` -------------------------------- ### Integrate FlexLayout with Carthage Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/index.html Specify FlexLayout in your Cartfile and run 'carthage update' to build the frameworks. Ensure FlexLayout.framework and YogaKit.framework are added to your project's Embedded Binaries. ```bash github "layoutBox/FlexLayout" ``` -------------------------------- ### Width and Height and Size Methods Source: https://github.com/layoutbox/flexlayout/blob/master/README.md Methods for setting the view's width, height, and size in pixels or percentages. These methods allow for precise control over element dimensions. ```APIDOC ## Width Methods ### Description Sets the view's width in pixels or as a percentage of its container's width. ### Method `width(_ width: CGFloat?)` `width(_ percent: FPercent)` ### Parameters - **width** (CGFloat?) - The width in pixels. Non-negative. `nil` to reset. - **percent** (FPercent) - The width as a percentage. Non-negative. ## Height Methods ### Description Sets the view's height in pixels or as a percentage of its container's height. ### Method `height(_ height: CGFloat?)` `height(_ percent: FPercent)` ### Parameters - **height** (CGFloat?) - The height in pixels. Non-negative. `nil` to reset. - **percent** (FPercent) - The height as a percentage. Non-negative. ## Size Methods ### Description Sets both the view's width and height simultaneously. ### Method `size(_ size: CGSize?)` `size(_ sideLength: CGFloat?)` ### Parameters - **size** (CGSize?) - The width and height in pixels. Non-negative. `nil` to reset. - **sideLength** (CGFloat?) - Sets width and height to the same pixel value, creating a square view. Non-negative. `nil` to reset. ``` -------------------------------- ### Padding Horizontal Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/Classes/Flex.html Sets the left, right, start, and end paddings to a specified value. ```APIDOC ## paddingHorizontal(_:) ### Description Sets the left, right, start and end paddings to the specified value. ### Method Swift ### Endpoint `paddingHorizontal(_ value: CGFloat) -> Flex` ### Parameters #### Path Parameters - **value** (CGFloat) - Required - The value to set for horizontal padding. ### Response #### Success Response (200) - **Flex** - The modified Flex instance for chaining. ### Request Example ```swift flexContainer.paddingHorizontal(10) ``` ### Response Example ```swift // Returns the Flex instance with horizontal padding applied ``` ``` -------------------------------- ### Integrate FlexLayout with Carthage Source: https://github.com/layoutbox/flexlayout/blob/master/README.md Use Carthage to manage FlexLayout dependencies. Ensure you build with --use-xcframeworks and add the resulting xcframework to your project. ```text github "layoutBox/FlexLayout" ``` ```bash carthage update --no-build (cd ./Carthage/Checkouts/FlexLayout && pod install) carthage build --use-xcframeworks ``` -------------------------------- ### Min/Max Width and Height Methods Source: https://github.com/layoutbox/flexlayout/blob/master/README.md Methods for setting minimum and maximum constraints for a view's width and height, providing finer control over layout behavior. ```APIDOC ## Min/Max Width Methods ### Description Sets the minimum and maximum width constraints for the view in pixels or percentages. ### Method `minWidth(_ width: CGFloat?)` `minWidth(_ percent: FPercent)` `maxWidth(_ width: CGFloat?)` `maxWidth(_ percent: FPercent)` ### Parameters - **width** (CGFloat?) - The minimum/maximum width in pixels. Non-negative. `nil` to reset. - **percent** (FPercent) - The minimum/maximum width as a percentage. Non-negative. ## Min/Max Height Methods ### Description Sets the minimum and maximum height constraints for the view in pixels or percentages. ### Method `minHeight(_ height: CGFloat?)` `minHeight(_ percent: FPercent)` `maxHeight(_ height: CGFloat?)` `maxHeight(_ percent: FPercent)` ### Parameters - **height** (CGFloat?) - The minimum/maximum height in pixels. Non-negative. `nil` to reset. - **percent** (FPercent) - The minimum/maximum height as a percentage. Non-negative. ``` -------------------------------- ### end(_:) Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex.html Sets the distance of the end edge (LTR=right, RTL=left) from the container's start edge in pixels. ```APIDOC ## end(_:) ### Description Set the end edge (LTR=right, RTL=left) distance from the container start edge in pixels. ### Declaration ```swift public func end(_ value: CGFloat) -> Flex ``` ``` -------------------------------- ### AlignItems Enumeration Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex/AlignItems.html The AlignItems enumeration defines the alignment of flex items along the cross axis. It can be set to stretch, start, center, end, or baseline. ```APIDOC ## AlignItems Enum Controls the alignment of flex items along the cross axis. ### Cases * **stretch** Default. Items are stretched to fit the container. #### Declaration ```swift case stretch ``` * **start** Items are positioned at the beginning of the container. #### Declaration ```swift case start ``` * **center** Items are positioned at the center of the container. #### Declaration ```swift case center ``` * **end** Items are positioned at the end of the container. #### Declaration ```swift case end ``` * **baseline** Items are positioned at the baseline of the container. #### Declaration ```swift case baseline ``` ``` -------------------------------- ### Set Horizontal Padding in FlexLayout Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex.html Use `paddingHorizontal(_:)` to set both left and right (or start and end) paddings to the same value. This method returns a modified Flex instance. ```Swift public func paddingHorizontal(_ value: CGFloat) -> Flex ``` -------------------------------- ### Apply Symmetric Insets with Shorthands Source: https://context7.com/layoutbox/flexlayout/llms.txt Use `horizontally(_:)`, `vertically(_:)`, and `all(_:)` for concise inset definitions. These are useful for absolute positioning to create margins or padding. ```swift let overlay = UIView() overlay.backgroundColor = UIColor.black.withAlphaComponent(0.5) // Stretch overlay to fill parent on all four sides (absolute positioning) overlay.flex .position(.absolute) .all(0) // Or set axis-specific insets let innerContent = UIView() innerContent.flex .position(.absolute) .vertically(20) .horizontally(16) ``` -------------------------------- ### Calculate Flex Item SizeThatFits Source: https://github.com/layoutbox/flexlayout/blob/master/README.md Get the size of a flex item when it is laid out within a container of a specified width. Use CGFloat.greatestFiniteMagnitude for the height to allow it to grow. ```swift let layoutSize = viewA.flex.sizeThatFits(size: CGSize(width: 200, height: CGFloat.greatestFiniteMagnitude)) ``` -------------------------------- ### Setting Width and Height Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/index.html Methods to set the view's width and height in pixels or as a percentage of its container. `width(nil)`, `height(nil)`, and `size(nil)` can be used to reset these properties. ```APIDOC ## Width and Height and Size FlexLayout has methods to set the view’s height and width. ### Methods: * **`width(_ width: CGFloat?)`** The value specifies the view’s width in pixels. The value must be non-negative. Call `width(nil)` to reset the property. * **`width(_ percent: FPercent)`** The value specifies the view’s width in percentage of its container width. The value must be non-negative. Call `width(nil)` to reset the property. * **`height(_ height: CGFloat?)`** The value specifies the view’s height in pixels. The value must be non-negative. Call `height(nil)` to reset the property. * **`height(_ percent: FPercent)`** The value specifies the view’s height in percentage of its container height. The value must be non-negative. Call `height(nil)` to reset the property. * **`size(_ size: CGSize?)`** The value specifies view’s width and the height in pixels. Values must be non-negative. Call `size(nil)` to reset the property. * **`size(_ sideLength: CGFloat?)`** The value specifies the width and the height of the view in pixels, creating a square view. Values must be non-negative. Call `size(nil)` to reset the property. ###### Usage examples: view.flex.width(100) view.flex.width(50%) view.flex.height(200) view.flex.size(250) ``` -------------------------------- ### top(), bottom(), left(), right(), start(), end() Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/index.html Properties to control the absolute positioning of a flex item within its parent. These methods define the distance from the parent's edges. ```APIDOC ## top(), bottom(), left(), right(), start(), end() ### Description A flex item which is `position` is set to `.absolute` is positioned absolutely in regards to its parent. This is done through 6 properties: Using these properties you can control the size and position of an absolute item within its parent. Because absolutely positioned children don’t affect their sibling’s layout. Absolute position can be used to create overlays and stack children in the Z axis. ### Methods * **`top( value: CGFloat)`**: Controls the distance a child’s top edge is from the parent’s top edge * **`bottom( value: CGFloat)`**: Controls the distance a child’s bottom edge is from the parent’s bottom edge * **`left( value: CGFloat)`**: Controls the distance a child’s left edge is from the parent’s left edge * **`right( value: CGFloat)`**: Controls the distance a child’s right edge is from the parent’s right edge * **`start( value: CGFloat)`**: Controls the distance a child’s start edge is from the parent’s start edge. In left-to-right direction (LTR), it corresponds to the `left()` property and in RTL to `right()` property. * **`end( value: CGFloat)`**: Controls the distance a child’s end edge is from the parent’s end edge. In left-to-right direction (LTR), it corresponds to the `right()` property and in RTL to `left()` property. ### Usage Examples ```swift view.flex.position(.absolute).top(10).right(10).width(100).height(50) ``` ``` -------------------------------- ### AlignContent Enumeration Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex/AlignContent.html The AlignContent enumeration defines how lines are packed within a flex container. It includes options for stretching, starting, centering, ending, and distributing space between or around lines. ```APIDOC ## AlignContent Enumeration Controls how lines are aligned within a flex container. ### Cases * **`stretch`** Default value. Lines stretch to take up the remaining space. #### Declaration Swift case stretch * **`start`** Lines are packed toward the start of the flex container. #### Declaration Swift case start * **`center`** Lines are packed toward the center of the flex container. #### Declaration Swift case center * **`end`** Lines are packed toward the end of the flex container. #### Declaration Swift case end * **`spaceBetween`** Lines are evenly distributed in the flex container. #### Declaration Swift case spaceBetween * **`spaceAround`** Lines are evenly distributed in the flex container, with half-size spaces on either end. #### Declaration Swift case spaceAround ``` -------------------------------- ### position() and related properties Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/index.html Enables absolute positioning for flex items, allowing precise placement within their parent using top, bottom, left, right, start, and end properties. ```APIDOC ## position(_: Position) ### Description The position property tells Flexbox how you want your item to be positioned within its parent. Position values: * **`relative (default)`** * **`absolute`**: The view is positioned using properties: top(), bottom(), left(), right(), start(), end(). ###### Usage examples: view.flex.position(.absolute).top(10).left(10).size(50) ## top(), bottom(), left(), right(), start(), end() ### Description A flex item which is `position` is set to `.absolute` is positioned absolutely in regards to its parent. This is done through 6 properties: * **`top( value: CGFloat)`**: Controls the distance a child’s top edge is from the parent’s top edge * **`bottom( value: CGFloat)`**: Controls the distance a child’s bottom edge is from the parent’s bottom edge * **`left( value: CGFloat)`**: Controls the distance a child’s left edge is from the parent’s left edge * **`right( value: CGFloat)`**: Controls the distance a child’s right edge is from the parent’s right edge * **`start( value: CGFloat)`**: Controls the distance a child’s start edge is from the parent’s start edge. In left-to-right direction (LTR), it corresponds to the `left()` property and in RTL to `right()` property. * **`end( value: CGFloat)`**: Controls the distance a child’s end edge is from the parent’s end edge. In left-to-right direction (LTR), it corresponds to the `right()` property and in RTL to `left()` property. Using these properties you can control the size and position of an absolute item within its parent. Because absolutely positioned children don’t affect their sibling’s layout. Absolute position can be used to create overlays and stack children in the Z axis. ###### Usage examples: view.flex.position(.absolute).top(10).right(10).width(100).height(50) ``` -------------------------------- ### JustifyContent Enumeration Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex/JustifyContent.html The JustifyContent enumeration defines the alignment of flex items along the main axis. It includes options for positioning items at the start, center, end, with space between them, or with space around them. ```APIDOC ## JustifyContent Enum Controls the alignment of flex items along the main axis. ### Cases * **`start`** Default value. Items are positioned at the beginning of the container. ```swift case start ``` * **`center`** Items are positioned at the center of the container. ```swift case center ``` * **`end`** Items are positioned at the end of the container. ```swift case end ``` * **`spaceBetween`** Items are positioned with space between the lines. ```swift case spaceBetween ``` * **`spaceAround`** Items are positioned with space before, between, and after the lines. ```swift case spaceAround ``` ``` -------------------------------- ### Setting Size Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/Classes/Flex.html Methods for setting both the width and height of a view. ```APIDOC ## size(_:) ### Description Sets the view's width and height in pixels. Values must be non-negative. ### Method `size(CGSize?) -> Flex` ### Parameters - **size** (CGSize?) - The desired width and height. ### Declaration ```swift public func size(_ size: CGSize?) -> Flex ``` ``` ```APIDOC ## size(_:) ### Description Sets the width and height of the view to the same value in pixels, creating a square view. Values must be non-negative. ### Method `size(CGFloat) -> Flex` ### Parameters - **sideLength** (CGFloat) - The length of each side for the square view. ### Declaration ```swift public func size(_ sideLength: CGFloat) -> Flex ``` ``` -------------------------------- ### AlignContent Enumeration Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/Classes/Flex/AlignContent.html The AlignContent enumeration defines how lines are packed within a flex container. It includes options for stretching, packing towards the start or end, centering, and distributing space evenly. ```APIDOC ## AlignContent Enumeration Controls how lines are aligned within a flex container when there is extra space. ### Cases * **`stretch`** Default value. Lines stretch to take up the remaining space. #### Declaration Swift case stretch * **`start`** Lines are packed toward the start of the flex container. #### Declaration Swift case start * **`center`** Lines are packed toward the center of the flex container. #### Declaration Swift case center * **`end`** Lines are packed toward the end of the flex container. #### Declaration Swift case end * **`spaceBetween`** Lines are evenly distributed in the flex container. #### Declaration Swift case spaceBetween * **`spaceAround`** Lines are evenly distributed in the flex container, with half-size spaces on either end. #### Declaration Swift case spaceAround ``` -------------------------------- ### addItem() / addItem(_ view: UIView) Source: https://context7.com/layoutbox/flexlayout/llms.txt `addItem()` creates a new anonymous `UIView`, adds it as a subview of the receiver, and returns its `Flex` interface. `addItem(_ view:)` does the same with an existing view. Both return the child's `Flex` for chaining. ```APIDOC ## addItem() / addItem(_ view: UIView) — Adding Flex Items `addItem()` creates a new anonymous `UIView`, adds it as a subview of the receiver, and returns its `Flex` interface. `addItem(_ view:)` does the same with an existing view. Both return the child's `Flex` for chaining. ```swift let root = UIView() let titleLabel = UILabel() titleLabel.text = "Hello, FlexLayout" root.flex.direction(.column).padding(12).define { flex in // Add an existing label as a flex item flex.addItem(titleLabel).marginBottom(8).grow(1) // Create an anonymous divider view inline flex.addItem() .height(1) .backgroundColor(.lightGray) // Create a row sub-container flex.addItem().direction(.row).justifyContent(.spaceBetween).define { flex in let leftBtn = UIButton(type: .system) leftBtn.setTitle("Cancel", for: .normal) let rightBtn = UIButton(type: .system) rightBtn.setTitle("OK", for: .normal) flex.addItem(leftBtn) flex.addItem(rightBtn) } } ``` ``` -------------------------------- ### Accessing Flex Item View and Setting Alpha Source: https://github.com/layoutbox/flexlayout/blob/master/README.md Access the underlying UIView of a flex item using `flex.view` within a `define` closure. This example sets the alpha of a nested item. ```swift view.flex.direction(.row).padding(20).alignItems(.center).define { (flex) in flex.addItem().width(50).height(50).define { (flex) in flex.view?.alpha = 0.8 } } ``` -------------------------------- ### Control Flex Item Sizing with `grow(_:)`, `shrink(_:)`, `basis(_:)` Source: https://context7.com/layoutbox/flexlayout/llms.txt Configure how flex items adjust their size. `grow` expands items, `shrink` contracts them, and `basis` sets their initial size. Use `shrink(0)` to prevent shrinking. ```swift let searchBar = UIView() let backButton = UIButton(type: .system) backButton.setTitle("←", for: .normal) let searchField = UITextField() searchField.placeholder = "Search…" let cancelButton = UIButton(type: .system) cancelButton.setTitle("Cancel", for: .normal) searchBar.flex.direction(.row).alignItems(.center).padding(8).gap(8).define { flex in // Fixed-size back button flex.addItem(backButton).width(32).height(32).shrink(0) // Search field grows to fill all available space flex.addItem(searchField) .grow(1) .shrink(1) .basis(0) .height(36) .paddingHorizontal(8) .backgroundColor(.systemGray6) .cornerRadius(8) // Fixed-size cancel button, never shrinks flex.addItem(cancelButton).shrink(0) } ``` -------------------------------- ### position(_: Position) Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/index.html Sets the positioning of a flex item within its parent. Can be relative (default) or absolute. When set to absolute, positioning is controlled by top(), bottom(), left(), right(), start(), and end() properties. ```APIDOC ## position(_: Position) ### Description The position property tells Flexbox how you want your item to be positioned within its parent. Position values: * **`relative (default)`** * **`absolute`**: The view is positioned using properties: top(), bottom(), left(), right(), start(), end(). ### Method `position(_: Position)` ### Usage Example ```swift view.flex.position(.absolute).top(10).left(10).size(50) ``` ``` -------------------------------- ### Layout Subviews with FlexLayout and PinLayout Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/index.html This Swift code demonstrates how to layout subviews using FlexLayout and PinLayout. It first pins the content view and root flex container, then lets the flexbox container lay itself out and adjust its height, and finally updates the scroll view's content size. ```swift override func layoutSubviews() { super.layoutSubviews() // 1) Layout the contentView & rootFlexContainer using PinLayout contentView.pin.top().bottom().left().right() rootFlexContainer.pin.top().left().right() // 2) Let the flexbox container layout itself and adjust the height rootFlexContainer.flex.layout(mode: .adjustHeight) // 3) Adjust the scrollview contentSize contentView.contentSize = rootFlexContainer.frame.size } ``` -------------------------------- ### Set Layout Direction for RTL/LTR Support in Swift Source: https://context7.com/layoutbox/flexlayout/llms.txt Configure the layout direction of a flex container to support bidirectional text. `start`/`end` margins and insets automatically adapt to the active direction. ```swift let rtlRow = UIView() let iconView = UIImageView() let textLabel = UILabel() textLabel.text = "مرحبا" // Force RTL layout for an Arabic UI section rtlRow.flex .direction(.row) .layoutDirection(.rtl) .alignItems(.center) .padding(12) .define { flex in flex.addItem(iconView).size(24).marginEnd(8) // marginEnd = right in RTL flex.addItem(textLabel).grow(1) } ``` -------------------------------- ### Set Margins Using UIEdgeInsets Source: https://github.com/layoutbox/flexlayout/blob/master/README.md Configure all margins at once using `UIEdgeInsets`. This is convenient for applying safe area insets or other predefined inset values. ```swift view.flex.margin(safeAreaInsets) ``` -------------------------------- ### JustifyContent Enum Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/Classes/Flex/JustifyContent.html The JustifyContent enumeration defines how flex items are aligned along the main axis of a flex container. It includes options for positioning items at the start, center, end, or distributing space between or around them. ```APIDOC ## JustifyContent Enumeration This enumeration controls the alignment of flex items along the main axis of a flex container. ### Cases * **`start`** Default value. Items are positioned at the beginning of the container. #### Declaration ```swift case start ``` * **`center`** Items are positioned at the center of the container. #### Declaration ```swift case center ``` * **`end`** Items are positioned at the end of the container. #### Declaration ```swift case end ``` * **`spaceBetween`** Items are positioned with space between the lines. #### Declaration ```swift case spaceBetween ``` * **`spaceAround`** Items are positioned with space before, between, and after the lines. #### Declaration ```swift case spaceAround ``` ``` -------------------------------- ### Alternative Flexbox Structure (without define) Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/index.html Achieves the same layout results as using the `define()` method but with a less elegant code structure. This approach requires manual creation and addition of container views. ```swift let columnContainer = UIView() columnContainer.flex.addItem(imageView).grow(1) view.flex.addItem(columnContainer) let rowContainer = UIView() rowContainer.flex.direction(.row) rowContainer.flex.addItem(titleLabel).grow(1) rowContainer.flex.addItem(priceLabel) columnContainer.flex.addItem(rowContainer) ``` -------------------------------- ### Setting Size Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex.html Allows setting both the width and height of a view simultaneously, either with a CGSize or a single value for a square view. ```APIDOC ## size(_:) ### Description The value specifies view’s width and the height in pixels. Values must be non-negative. ### Method `size(CGSize?) -> Flex` ## size(_:) ### Description The value specifies the width and the height of the view in pixels, creating a square view. Values must be non-negative. ### Method `size(CGFloat) -> Flex` ``` -------------------------------- ### Absolute Positioning Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/index.html Set a flex item to `.absolute` positioning to control its placement using top, bottom, left, right, start, and end properties, independent of sibling layouts. This is useful for overlays and Z-axis stacking. ```swift view.flex.position(.absolute).top(10).left(10).size(50) ``` ```swift view.flex.position(.absolute).top(10).right(10).width(100).height(50) ``` -------------------------------- ### Setting Minimum and Maximum Dimensions Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/index.html Methods to set minimum and maximum width and height constraints for a view, either in pixels or as a percentage. These methods help control the dynamic sizing of items within a layout. ```APIDOC ### minWidth(), maxWidth(), minHeight(), maxHeight() FlexLayout has methods to set the view’s minimum and maximum width, and minimum and maximum height. Using minWidth, minHeight, maxWidth, and maxHeight gives you increased control over the final size of items in a layout. By mixing these properties with `grow`, `shrink`, and `alignItems(.stretch)`, you are able to have items with dynamic size within a range which you control. An example of when Max properties can be useful is if you are using `alignItems(.stretch)` but you know that your item won’t look good after it increases past a certain point. In this case, your item will stretch to the size of its parent or until it is as big as specified in the Max property. Same goes for the Min properties when using `shrink`. For example, you may want children of a container to shrink to fit on one row, but if you specify a minimum width, they will break to the next line after a certain point (if you are using `wrap(.wrap)`. Another case where Min and Max dimension constraints are useful is when using `aspectRatio`. **Methods:** * **`minWidth(_ width: CGFloat?)`** The value specifies the view’s minimum width of the view in pixels. The value must be non-negative. Call `minWidth(nil)` to reset the property. * **`minWidth(_ percent: FPercent)`** The value specifies the view’s minimum width of the view in percentage of its container width. The value must be non-negative. Call `minWidth(nil)` to reset the property.. * **`maxWidth(_ width: CGFloat?)`** The value specifies the view’s maximum width of the view in pixels. The value must be non-negative. Call `maxWidth(nil)` to reset the property. * **`maxWidth(_ percent: FPercent)`** The value specifies the view’s maximum width of the view in percentage of its container width. The value must be non-negative. Call `maxWidth(nil)` to reset the property. * **`minHeight(_ height: CGFloat?)`** The value specifies the view’s minimum height of the view in pixels. The value must be non-negative. Call `minHeight(nil)` to reset the property. * **`minHeight(_ percent: FPercent)`** The value specifies the view’s minimum height of the view in percentage of its container height. The value must be non-negative. Call `minHeight(nil)` to reset the property. * **`maxHeight(_ height: CGFloat?)`** The value specifies the view’s maximum height of the view in pixels. The value must be non-negative. Call `maxHeight(nil)` to reset the property. * **`maxHeight(_ percent: FPercent)`** The value specifies the view’s maximum height of the view in percentage of its container height. The value must be non-negative. Call `maxHeight(nil)` to reset the property. ###### Usage examples: view.flex.maxWidth(200) view.flex.maxWidth(50%) view.flex.width(of: view1).maxWidth(250) view.flex.maxHeight(100) view.flex.height(of: view1).maxHeight(30%) ``` -------------------------------- ### padding (individual) Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/docsets/FlexLayout.docset/Contents/Resources/Documents/Classes/Flex.html Set the individually top, left, bottom and right paddings. ```APIDOC ## padding(_:_:_:_:) ### Description Set the individually top, left, bottom and right paddings. ### Method public func padding(_ top: CGFloat, _ left: CGFloat, _ bottom: CGFloat, _ right: CGFloat) -> Flex ``` -------------------------------- ### Center Buttons with Margin in FlexContainer (Swift) Source: https://github.com/layoutbox/flexlayout/blob/master/README.md This example demonstrates centering three buttons within a flex container, with a specified margin between the second and third buttons. It utilizes `justifyContent(.center)` and `marginTop()` for layout control. ```swift rootFlexContainer.flex.justifyContent(.center).padding(10).define { flex.addItem(button1) flex.addItem(button2).marginTop(10) flex.addItem(button3).marginTop(10) } ``` -------------------------------- ### Align Items Along Main Axis Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/index.html The `justifyContent` property defines the alignment of flex items along the main-axis. Use values like `start`, `end`, `center`, `spaceBetween`, or `spaceAround` to distribute extra free space. ```swift view.flex.justifyContent(.start) // defaut value. view.flex.justifyContent(.center) ``` -------------------------------- ### Apply Visual Styling with backgroundColor, cornerRadius, border Source: https://context7.com/layoutbox/flexlayout/llms.txt Use chained convenience methods like `backgroundColor(_:)`, `cornerRadius(_:)`, and `border(_:_:)` to apply common `UIView` layer properties directly within a FlexLayout definition chain. ```swift let pill = UIView() let pillLabel = UILabel() pillLabel.text = "Active" pillLabel.textColor = .white pillLabel.font = .boldSystemFont(ofSize: 12) pill.flex .direction(.row) .justifyContent(.center) .alignItems(.center) .padding(6, 14) .backgroundColor(.systemGreen) .cornerRadius(16) .border(1.5, UIColor.white.withAlphaComponent(0.4)) .define { flex in flex.addItem(pillLabel) } ``` -------------------------------- ### Center Views in a Flex Container Source: https://github.com/layoutbox/flexlayout/blob/master/docs/1.1/index.html This example demonstrates how to center three views vertically within a flex container using `justifyContent(.center)` and `padding`. Each view is set to a height of 40 pixels with a 10-pixel top margin. ```swift rootFlexContainer.flex.justifyContent(.center).padding(10).define { flex.addItem(button1).height(40).marginTop(10) flex.addItem(button2).height(40).marginTop(10) flex.addItem(button3).height(40).marginTop(10) } ```