Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add border function in Flex class #216

Merged
merged 3 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,8 @@ FlexLayout also adds methods to set common UIView properties.
Set the flex item's UIView background color.
* **`cornerRadius(_ value: CGFloat)`**
Set the flex item's UIView rounded corner radius.
* **`border(_ width: CGFloat, _ color: UIColor)`**
Set the flex item's UIView border.

###### Usage examples:
```swift
Expand All @@ -1006,6 +1008,8 @@ Set the flex item's UIView rounded corner radius.
}
// Set rounded corner
flex.addItem().cornerRadius(12)
// Set border
flex.addItem().border(1, .black)
```

<br>
Expand Down
21 changes: 19 additions & 2 deletions Sources/Swift/FlexLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ public final class Flex {
Note that row and row-reverse are affected by the layout direction (see `layoutDirection` property) of the flex container.
If its text direction is LTR (left to right), row represents the horizontal axis oriented from left to right, and row-reverse
from right to left; if the direction is rtl, it's the opposite.

- Parameter value: Default value is .column
*/
public var direction: Direction? {
get {
Expand Down Expand Up @@ -1250,6 +1248,25 @@ public final class Flex {
preconditionFailure("Trying to modify deallocated host view")
}
}

/**
Set the view to border width and color

- Parameters:
- width: border width
- color: border color
- Returns: flex interface
*/
@discardableResult
public func border(_ width: CGFloat, _ color: UIColor) -> Flex {
if let host = self.view {
host.layer.borderWidth = width
host.layer.borderColor = color.cgColor
return self
} else {
preconditionFailure("Trying to modify deallocated host view")
}
}

//
// MARK: Display
Expand Down