From f800ecc5d22a2d0590d9ad5f0800732ba4628ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=82=85=E6=B5=AA?= Date: Thu, 13 Apr 2017 22:55:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E6=B3=9B?= =?UTF-8?q?=E5=9E=8B=E6=96=B9=E6=B3=95=E3=80=82=E7=94=A8=E4=BA=8E=E7=B1=BB?= =?UTF-8?q?=E4=BC=BCCSS=E5=AE=9A=E4=B9=89=E5=9F=BA=E7=A1=80=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=80=E6=A0=B7=EF=BC=8C=E5=8F=AF=E9=A2=84=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=A4=9A=E4=B8=AA=E5=9F=BA=E7=A1=80=E7=9A=84style?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=97=B6=E9=9A=8F=E6=84=8F=E7=BB=84?= =?UTF-8?q?=E5=90=88=E6=88=90=E4=B8=80=E4=B8=AA=E9=9B=86=E5=90=88=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/Source/ViewViewController.swift | 21 ++++++++++++++++++--- Source/Core/UIViewStyle.swift | 8 ++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Example/Source/ViewViewController.swift b/Example/Source/ViewViewController.swift index ff25f8a..d412e71 100644 --- a/Example/Source/ViewViewController.swift +++ b/Example/Source/ViewViewController.swift @@ -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() { @@ -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) @@ -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), diff --git a/Source/Core/UIViewStyle.swift b/Source/Core/UIViewStyle.swift index 4c6e0c0..a1389cd 100644 --- a/Source/Core/UIViewStyle.swift +++ b/Source/Core/UIViewStyle.swift @@ -32,6 +32,14 @@ extension UIView { } } + public func mi_updateStyles(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)!