Latest 0.1.2
Homepage https://github.com/tomasmikeska/SwiftyBeans
License MIT
Platforms ios 10.0
Authors

Language: Swift 4
Platform: iOS 10+
CocoaPods compatible
License: MIT

SwiftyBeans is a μlibrary for declarative iOS view styling. Write reusable, readable
and concise styles.

Usage

let paragraphStyle: Style = .bean(
    .textColor(.black),
    .font("Avenir-Light"),
    .fontSize(20),
    .multiline
)

let accentTextStyle: Style = .bean(
    .paragraphStyle,
    .textColor(.blue)
)

label.style(accentTextStyle, .textAlign(.justified))

Documentation

All attributes used are placed in the Style enum.

Beans

Beans are a metaphor for style modules. Beans simply wrap any number of
styles or another beans as bean is technically a style as well.

let module: Style = .bean(anotherBean, andAnotherBean, .backgroundColor(.red))

UIView Attributes

Background color

.backgroundColor(UIColor)

Background image

.backgroundImage(UIImage?)

Content mode

.contentMode(UIViewContentMode)

Clips to bounds

.clipsToBounds(Bool)

Scale

.scale(CGFloat)
// -- or
.scaleX(CGFloat)
// -- or
.scaleY(CGFloat)

Translate

// First argument is axis, second y axis
.translate(CGFloat, CGFloat)
// -- or
.translateX(CGFloat)
// -- or
.translateY(CGFloat)

Rotate

.rotate(CGFloat)

Alpha (opacity)

.alpha(CGFloat)

Visibility

.visible
.invisible

Z-index (z-axis elevation)

.zIndex(CGFloat)

Box shadow

.shadow(color: UIColor = .black,
        opacity: Float = 0.3,
        verticalOffset: CGFloat = 0,
        horizontalOffset: CGFloat = 0,
        offset: CGSize? = nil,
        radius: CGFloat = 8)

Border

.border(thick: CGFloat = 1.0, color: UIColor = .black)

One-sided border

.border(edges: UIRectEdge, thick: CGFloat = 1.0, color: UIColor = .black)

// -- Example usage

.border(edges: [.top, .bottom])

Corner radius

.cornerRadius(CGFloat)

Single corner radius
(NOTE: Works only on iOS 11.0+, fallbacks to setting radius on all corners)

.cornerRadius(corner: Corner, _ radius: CGFloat)

Linear gradient

.linearGradient(direction: GradientDirection = .toBottom,
                locations: [NSNumber]? = nil,
                _ colors: UIColor...)

// -- Example usage

.linearGradient(direction: .toRight, .blue, .white)

UIImageView Attributes

Image

.image(UIImage?)

UILabel Attributes

Text color

.textColor(UIColor)

UIFont

.font(UIFont)

// -- or

.fontName(String)

Font size

.fontSize(CGFloat)

Text align

.textAlign(NSTextAlignment)

Number of lines

// Sets UILabels numberOfLines to 0
.multiline

// -- or

.numberOfLines(Int)

🎉🎉

Instalation

SwiftyBeans doesn’t contain any external dependencies.

CocoaPods

# Podfile
pod 'SwiftyBeans'

Then in the Podfile directory:

$ pod install

License

SwiftyBeans is released under the MIT License. Please see the LICENSE file for details.

Latest podspec

{
    "name": "SwiftyBeans",
    "version": "0.1.2",
    "summary": "Declarative view styles with Swift",
    "description": "Declarative view styles with Swift. Write reusable, readable and concise styles.",
    "homepage": "https://github.com/tomasmikeska/SwiftyBeans",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Tomu00e1u0161 Mikeska": "[email protected]"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/tomasmikeska/SwiftyBeans.git",
        "tag": "0.1.2"
    },
    "source_files": "Sources/**/*.swift"
}

Pin It on Pinterest

Share This