Skip to content
Open
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
21 changes: 18 additions & 3 deletions Example/Source/ViewViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import UIKit
import ViewStyle

let redBackground:[MIProperty: Any] = [.backgroundColor: UIColor.red]
let blueBorder: [MIProperty: Any] = [.layerBorderWidth: 1.0,
.layerBorderColor: UIColor.blue.cgColor]

class ViewViewController: UIViewController {

override func viewDidLoad() {
Expand All @@ -25,7 +29,8 @@ class ViewViewController: UIViewController {

let view2 = UIView(frame: CGRect(x: 10, y: 220, width: 200, height: 100))
view2.backgroundColor = UIColor.blue
view2.mi_styles = self.normalStyle
// view2.mi_styles = self.normalStyle
view2.mi_updateStyles(styles: self.testStyleGroup)
view2.mi_styles = self.layerStyle
self.view.addSubview(view2)

Expand All @@ -50,11 +55,21 @@ extension ViewViewController {
]
}

var testStyleGroup: [(MIProperty, Any)] {
return [redBackground,
[.alpha: 0.5],
[.isOpaque: true,
.tintAdjustmentMode: UIViewTintAdjustmentMode.automatic,
.clipsToBounds: true
],
blueBorder,
layerStyle
].flatMap({ $0 })
}

var layerStyle: [MIProperty: Any] {
return [
.clipsToBounds: false,
.layerBorderWidth: 1.0,
.layerBorderColor: UIColor.red.cgColor,
.layerShadowRadius: 4.0,
.layerShadowColor: UIColor.green.cgColor,
.layerShadowOffset: CGSize(width: 10, height: 10),
Expand Down
8 changes: 8 additions & 0 deletions Source/Core/UIViewStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ extension UIView {
}
}

public func mi_updateStyles<S: Sequence>(styles: S)
where S.Iterator.Element == (MIProperty, Any) {
print(styles)
for (key, value) in styles {
mi_setValue(value, forKey: key.rawValue)
}
}

open func mi_setValue(_ value: Any, forKey key: String) {

let style = MIProperty(rawValue: key)!
Expand Down