├── .gitignore ├── CustomView.md ├── CustomView.podspec ├── CustomViewKit ├── AutoLayoutExtension.swift ├── CustomViewKit.h ├── CustomViewLayer.swift ├── CustomViewLayerStyle.swift ├── CustomViewLight.swift ├── CustomViewSource.swift ├── Info.plist ├── LICENSE ├── Reflect.swift ├── StringExtension.swift ├── ViewSources.swift └── ViewStyle.swift ├── CustomViewKitExample ├── PodTest.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── PodTest.xcworkspace │ └── contents.xcworkspacedata ├── PodTest │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── CV1.swift │ ├── CV2.swift │ ├── CV2.xib │ ├── CustomViewKitExtension.swift │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ └── ViewController.swift ├── PodTestTests │ ├── Info.plist │ └── PodTestTests.swift ├── Podfile ├── Podfile.lock └── Pods │ ├── CustomView │ ├── CustomViewKit │ │ ├── AutoLayoutExtension.swift │ │ ├── CustomViewLayer.swift │ │ ├── CustomViewLayerStyle.swift │ │ ├── CustomViewLight.swift │ │ ├── CustomViewSource.swift │ │ ├── Reflect.swift │ │ ├── StringExtension.swift │ │ ├── ViewSources.swift │ │ └── ViewStyle.swift │ ├── LICENSE │ └── README.md │ ├── Manifest.lock │ ├── Pods.xcodeproj │ └── project.pbxproj │ └── Target Support Files │ ├── Pods-CustomView │ ├── Info.plist │ ├── Pods-CustomView-Private.xcconfig │ ├── Pods-CustomView-dummy.m │ ├── Pods-CustomView-prefix.pch │ ├── Pods-CustomView-umbrella.h │ ├── Pods-CustomView.modulemap │ └── Pods-CustomView.xcconfig │ └── Pods │ ├── Info.plist │ ├── Pods-acknowledgements.markdown │ ├── Pods-acknowledgements.plist │ ├── Pods-dummy.m │ ├── Pods-environment.h │ ├── Pods-frameworks.sh │ ├── Pods-resources.sh │ ├── Pods-umbrella.h │ ├── Pods.debug.xcconfig │ ├── Pods.modulemap │ └── Pods.release.xcconfig ├── CustomViewObjc ├── CustomViewObjc-Prefix.pch ├── CustomViewObjc.h ├── CustomViewObjetiveC.h ├── CustomViewObjetiveC.m ├── CustomViewObjetiveC.xib ├── CustomViewTemplate.h ├── CustomViewTemplate.m ├── CustomWithXibLiveRenderKVC.h ├── CustomWithXibLiveRenderKVC.m ├── CustomWithXibLiveRenderKVC.xib ├── Info.plist ├── ViewSource.h └── ViewSource.m ├── CustomViewObjcTests ├── CustomViewObjcTests.m └── Info.plist ├── CustomViewSwift ├── CustomViewSwift.h ├── CustomViewTemplate.swift ├── CustomViewWithSwift.swift ├── Info.plist ├── LiveRenderKVC.swift ├── LiveRenderKVC.xib └── ViewSource.swift ├── CustomViewSwiftTests ├── CustomViewSwiftTests.swift └── Info.plist ├── CustomViewTest.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── CustomViewTest.xccheckout │ └── xcuserdata │ │ ├── APP559.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── yume.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── APP559.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ ├── CustomViewObjc.xcscheme │ │ ├── CustomViewSwift.xcscheme │ │ ├── CustomViewTest.xcscheme │ │ └── xcschememanagement.plist │ └── yume.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── CustomViewObjc.xcscheme │ ├── CustomViewSwift.xcscheme │ ├── CustomViewTest.xcscheme │ └── xcschememanagement.plist ├── CustomViewTest ├── Base.lproj │ └── Main.storyboard ├── Custom.h ├── Custom.m ├── CustomViewTest-Info.plist ├── CustomViewTest-Prefix.pch ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── MyPlayground.playground │ ├── contents.xcplayground │ ├── section-1.swift │ └── timeline.xctimeline ├── TemplateView1.h ├── TemplateView1.m ├── TemplateView1.xib ├── en.lproj │ ├── Gpro_icon(512x512).png │ └── InfoPlist.strings ├── main.m ├── yumeAppDelegate.h ├── yumeAppDelegate.m ├── yumeViewController.h ├── yumeViewController.m └── zh-Hant.lproj │ ├── InfoPlist.strings │ └── Main.strings ├── CustomViewTestTests ├── CustomViewTestTests-Info.plist ├── CustomViewTestTests.m ├── en.lproj │ └── InfoPlist.strings └── zh-Hant.lproj │ └── InfoPlist.strings ├── CustomView_LiveRender_KVC.md ├── KVC.md ├── LICENSE ├── LiveRender.md ├── README.md ├── WWDC_2014_Session_401.md └── images ├── i1.png ├── i2.png ├── i3.png └── i5.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### OSX ### 4 | .DS_Store 5 | .AppleDouble 6 | .LSOverride 7 | 8 | # Icon must end with two \r 9 | Icon 10 | 11 | 12 | # Thumbnails 13 | ._* 14 | 15 | # Files that might appear on external disk 16 | .Spotlight-V100 17 | .Trashes 18 | 19 | # Directories potentially created on remote AFP share 20 | .AppleDB 21 | .AppleDesktop 22 | Network Trash Folder 23 | Temporary Items 24 | .apdisk 25 | 26 | 27 | ### Xcode ### 28 | build/ 29 | *.pbxuser 30 | !default.pbxuser 31 | *.mode1v3 32 | !default.mode1v3 33 | *.mode2v3 34 | !default.mode2v3 35 | *.perspectivev3 36 | !default.perspectivev3 37 | xcuserdata 38 | *.xccheckout 39 | *.moved-aside 40 | DerivedData 41 | *.xcuserstate 42 | 43 | 44 | ### Objective-C ### 45 | # Xcode 46 | # 47 | build/ 48 | *.pbxuser 49 | !default.pbxuser 50 | *.mode1v3 51 | !default.mode1v3 52 | *.mode2v3 53 | !default.mode2v3 54 | *.perspectivev3 55 | !default.perspectivev3 56 | xcuserdata 57 | *.xccheckout 58 | *.moved-aside 59 | DerivedData 60 | *.hmap 61 | *.ipa 62 | *.xcuserstate 63 | 64 | # CocoaPods 65 | # 66 | # We recommend against adding the Pods directory to your .gitignore. However 67 | # you should judge for yourself, the pros and cons are mentioned at: 68 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 69 | # 70 | # Pods/ 71 | -------------------------------------------------------------------------------- /CustomView.md: -------------------------------------------------------------------------------- 1 | # Custom View With xib (IOS 7 & 8) 2 | 3 | 中文版:[IOS Custom View Part 1](http://yume190.github.io/2014/09/26/IOS-Custom-View-Part-1/) 4 | 5 | Related Documents 6 | 7 | * [CustomView.h](CustomViewTest/TemplateView1.h) 8 | * [CustomView.m](CustomViewTest/TemplateView1.m) 9 | * [CustomView.xib](CustomViewTest/TemplateView1.xib) 10 | 11 | ### Step 1 12 | * Create a CustomView class inherit from UIView.(ex:CustomView.h & CustomView.m) 13 | * Then create xib file with same name.(ex:CustomView.xib) 14 | 15 | ### Step 2 16 | * Click the xib file 17 | * Find the File's Owner and click it 18 | * command + option + 3 19 | * Input your Custom Class name.(ex:CustomView) 20 | 21 | ### Step 3 22 | * Implement `initWithCoder` method 23 | 24 |
- (void) setup{
25 |     NSString *nibName = NSStringFromClass([self class]);
26 |     UINib *nib = [UINib nibWithNibName:nibName bundle:nil];
27 |     [nib instantiateWithOwner:self options:nil];
28 |     //Add the view loaded from the nib into self.
29 |     [self addSubview:self.view];
30 | }
31 | 
32 | - (id)initWithCoder:(NSCoder *)aDecoder{
33 |     self = [super initWithCoder:aDecoder];
34 | 
35 |     if (self) {
36 |         [self setup];
37 |     }
38 |     return self;
39 | }
40 | 
41 | 42 | ### Step 4 (Optional) 43 | * If you want to input your parameter at storyboard. 44 | * Drag a UIView to your storyboard. 45 | * Click it -> command + option + 3 -> input your Custom Class name 46 | * Find the "User denfined Runtime Attributes" 47 | * enter the parameter you want 48 | 49 | ex: String vTitle = "the title" 50 | 51 | | Key Path | Type | Value | 52 | | :------------ |:--------------|:--------| 53 | |vTitle |String |the title| 54 | 55 | * Create a property in CustomView.h 56 | 57 |
@property (assign) NSString* vTitle;
58 | 59 | * Implement `awakeFromNib` in CustomView.m 60 | 61 |
- (void)awakeFromNib {
62 |     labelTitle.text = vTitle;
63 | }
64 | -------------------------------------------------------------------------------- /CustomView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'CustomView' 3 | s.version = '1.4' 4 | s.license = 'MIT' 5 | s.summary = "A Light weight Lib, custom a view with xib & live render" 6 | s.homepage = 'https://github.com/yume190/CustomView' 7 | s.authors = { 'yume190' => 'yume190@gmail.com' } 8 | s.social_media_url = "https://www.facebook.com/yume190" 9 | s.source = { :git => 'https://github.com/yume190/CustomView.git', :tag => s.version } 10 | #s.ios.deployment_target = '8.0' 11 | s.platform = :ios, "8.0" 12 | s.source_files = 'CustomViewKit/*.swift' 13 | s.requires_arc = true 14 | end 15 | 16 | -------------------------------------------------------------------------------- /CustomViewKit/AutoLayoutExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AutoLayoutExtension.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/3/14. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public struct LayoutAttribute { 12 | public var view:UIView? 13 | public var attribute:NSLayoutAttribute 14 | public var multiplier:CGFloat 15 | public var constant:CGFloat 16 | 17 | init(view:UIView, attribute: NSLayoutAttribute, constant:CGFloat = 0, multiplier:CGFloat = 1.0){ 18 | self.view = view; 19 | self.attribute = attribute 20 | self.multiplier = multiplier 21 | self.constant = constant; 22 | } 23 | 24 | } 25 | 26 | public extension UIView { 27 | 28 | func addConstraints (constraints: NSLayoutConstraint...){ 29 | for constraint in constraints { 30 | self.addConstraint(constraint) 31 | } 32 | } 33 | 34 | public var width : LayoutAttribute { 35 | get { return LayoutAttribute(view: self, attribute : .Width); } 36 | } 37 | 38 | public var height : LayoutAttribute { 39 | get { return LayoutAttribute(view: self, attribute : .Height); } 40 | } 41 | 42 | public var leading : LayoutAttribute { 43 | get { return LayoutAttribute(view: self, attribute : .Leading); } 44 | } 45 | 46 | public var trailing : LayoutAttribute { 47 | get { return LayoutAttribute(view: self, attribute : .Trailing); } 48 | } 49 | 50 | public var top : LayoutAttribute { 51 | get { return LayoutAttribute(view: self, attribute : .Top); } 52 | } 53 | 54 | public var bottom : LayoutAttribute { 55 | get { return LayoutAttribute(view: self, attribute : .Bottom); } 56 | } 57 | 58 | public var centerX : LayoutAttribute { 59 | get { return LayoutAttribute(view: self, attribute : .CenterX); } 60 | } 61 | 62 | public var centerY : LayoutAttribute { 63 | get { return LayoutAttribute(view: self, attribute : .CenterY); } 64 | } 65 | 66 | } 67 | 68 | public func == (left: LayoutAttribute, right: LayoutAttribute) -> NSLayoutConstraint { 69 | var layoutConstraint = NSLayoutConstraint(item:left.view!, 70 | attribute: left.attribute, relatedBy: NSLayoutRelation.Equal, toItem: right.view, 71 | attribute: right.attribute, multiplier: right.multiplier, constant: right.constant) 72 | 73 | return layoutConstraint 74 | } 75 | 76 | public func >= (left: LayoutAttribute, right: LayoutAttribute) -> NSLayoutConstraint { 77 | var layoutConstraint = NSLayoutConstraint(item: left.view!, 78 | attribute: left.attribute, relatedBy: NSLayoutRelation.GreaterThanOrEqual, toItem: right.view, attribute: right.attribute, 79 | multiplier: right.multiplier, constant: right.constant); 80 | return layoutConstraint 81 | } 82 | 83 | public func <= (left: LayoutAttribute, right: LayoutAttribute) -> NSLayoutConstraint { 84 | var layoutConstraint = NSLayoutConstraint(item: left.view!, 85 | attribute: left.attribute, relatedBy: NSLayoutRelation.LessThanOrEqual, toItem: right.view, attribute: right.attribute, 86 | multiplier: right.multiplier, constant: right.constant); 87 | return layoutConstraint 88 | } 89 | 90 | public func == (left: LayoutAttribute, right: CGFloat) -> NSLayoutConstraint { 91 | var layoutConstraint = NSLayoutConstraint(item:left.view!, 92 | attribute: left.attribute, relatedBy: NSLayoutRelation.Equal, toItem: nil, 93 | attribute: .NotAnAttribute, multiplier: 1.0, constant: right) 94 | 95 | return layoutConstraint 96 | } 97 | 98 | public func <= (left: LayoutAttribute, right: CGFloat) -> NSLayoutConstraint { 99 | var layoutConstraint = NSLayoutConstraint(item:left.view!, 100 | attribute: left.attribute, relatedBy: NSLayoutRelation.LessThanOrEqual, toItem: nil, 101 | attribute: .NotAnAttribute, multiplier: 1.0, constant: right) 102 | 103 | return layoutConstraint 104 | } 105 | 106 | public func >= (left: LayoutAttribute, right: CGFloat) -> NSLayoutConstraint { 107 | var layoutConstraint = NSLayoutConstraint(item:left.view!, 108 | attribute: left.attribute, relatedBy: NSLayoutRelation.GreaterThanOrEqual, toItem: nil, 109 | attribute: .NotAnAttribute, multiplier: 1.0, constant: right) 110 | 111 | return layoutConstraint 112 | } 113 | 114 | // ------------------------------------------ 115 | 116 | infix operator *+ { 117 | associativity left 118 | precedence 150 119 | } 120 | 121 | public func *+(left: LayoutAttribute, right: (multiplier:CGFloat, contant:CGFloat)) -> LayoutAttribute { 122 | var layoutAttribute = LayoutAttribute(view:left.view!, attribute: left.attribute, constant: right.contant, multiplier:right.multiplier) 123 | return layoutAttribute 124 | } 125 | 126 | public func *(left: LayoutAttribute, right: CGFloat) -> LayoutAttribute { 127 | var layoutAttribute = LayoutAttribute(view:left.view!, attribute: left.attribute, constant: 0, multiplier:right) 128 | return layoutAttribute 129 | } 130 | 131 | public func +(left: LayoutAttribute, right: CGFloat) -> LayoutAttribute { 132 | var layoutAttribute = LayoutAttribute(view:left.view!, attribute: left.attribute, constant: right, multiplier:left.multiplier) 133 | return layoutAttribute 134 | } 135 | 136 | public func -(left: LayoutAttribute, right: CGFloat) -> LayoutAttribute { 137 | var layoutAttribute = LayoutAttribute(view:left.view!, attribute: left.attribute, constant: -right, multiplier:left.multiplier) 138 | return layoutAttribute 139 | } 140 | 141 | infix operator <~ { 142 | associativity left 143 | precedence 125 144 | } 145 | 146 | public func <~ (left: NSLayoutConstraint, right: UILayoutPriority) -> NSLayoutConstraint { 147 | left.priority = right 148 | return left 149 | } 150 | 151 | infix operator <- { 152 | associativity right 153 | precedence 90 154 | } 155 | 156 | public func <- (left: UIView, right: NSLayoutConstraint) -> UIView { 157 | left.addConstraint(right) 158 | return left 159 | } 160 | -------------------------------------------------------------------------------- /CustomViewKit/CustomViewKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewKit.h 3 | // CustomViewKit 4 | // 5 | // Created by Yume on 2015/3/22. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for CustomViewKit. 12 | FOUNDATION_EXPORT double CustomViewKitVersionNumber; 13 | 14 | //! Project version string for CustomViewKit. 15 | FOUNDATION_EXPORT const unsigned char CustomViewKitVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /CustomViewKit/CustomViewLayer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomView2.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/3/20. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @IBDesignable 12 | public class CustomViewLayer: CustomViewSource { 13 | 14 | @IBInspectable public var borderColor: UIColor? { 15 | didSet { 16 | if let color = borderColor { 17 | layer.borderColor = color.CGColor 18 | } 19 | } 20 | } 21 | @IBInspectable public var borderWidth: CGFloat = CGFloat.infinity { didSet { layer.borderWidth = borderWidth }} 22 | 23 | @IBInspectable public var cornerRadius: CGFloat = CGFloat.infinity { didSet { layer.cornerRadius = cornerRadius }} 24 | 25 | @IBInspectable public var shadowColor: UIColor? { 26 | didSet { 27 | if let color = shadowColor{ 28 | layer.shadowColor = color.CGColor 29 | } 30 | } 31 | } 32 | @IBInspectable public var shadowRadius: CGFloat = CGFloat.infinity { didSet { layer.shadowRadius = shadowRadius }} 33 | @IBInspectable public var shadowOpacity: Float = Float.infinity { didSet { layer.shadowOpacity = shadowOpacity }} 34 | @IBInspectable public var shadowOffsetY: CGFloat = CGFloat.infinity { didSet { layer.shadowOffset.height = shadowOffsetY }} 35 | 36 | } 37 | -------------------------------------------------------------------------------- /CustomViewKit/CustomViewLayerStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomView2.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/3/20. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @IBDesignable 12 | public class CustomViewLayerStyle: CustomViewLayer { 13 | 14 | @IBInspectable public var style:String = "none" { 15 | didSet{ 16 | if let _style = ViewStyleInstance.valueForKey(style) as? ViewStyle { 17 | _viewStyle = _style 18 | } 19 | } 20 | } 21 | 22 | } 23 | 24 | // MARK: Style 25 | public extension CustomViewLayerStyle { 26 | private func setViewStyle(vStyle:ViewStyle){ 27 | println("set style") 28 | 29 | if let _borderColor = borderColor?.CGColor ?? vStyle.borderColor?.CGColor { 30 | layer.borderColor = _borderColor 31 | } 32 | 33 | if let _borderWidth = borderWidth != CGFloat.infinity ? borderWidth : vStyle.borderWidth { 34 | layer.borderWidth = _borderWidth 35 | } 36 | 37 | if let _cornerRadius = cornerRadius != CGFloat.infinity ? cornerRadius : vStyle.cornerRadius { 38 | layer.cornerRadius = _cornerRadius 39 | } 40 | 41 | if let _shadowRadius = shadowRadius != CGFloat.infinity ? shadowRadius : vStyle.shadowRadius{ 42 | layer.shadowRadius = _shadowRadius 43 | } 44 | 45 | if let _shadowColor = shadowColor?.CGColor ?? vStyle.shadowColor?.CGColor{ 46 | layer.shadowColor = _shadowColor 47 | } 48 | 49 | if let _shadowOpacity = shadowOpacity != Float.infinity ? shadowOpacity: vStyle.shadowOpacity{ 50 | layer.shadowOpacity = _shadowOpacity 51 | } 52 | 53 | if let _shadowOffsetY = shadowOffsetY != CGFloat.infinity ? shadowOffsetY : vStyle.shadowOffsetY{ 54 | layer.shadowOffset.height = _shadowOffsetY 55 | } 56 | } 57 | 58 | private var _viewStyle:ViewStyle{ 59 | set{ setViewStyle(newValue) } 60 | get{ return ViewStyleInstance.none() } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /CustomViewKit/CustomViewLight.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomView2.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/3/20. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @IBDesignable 12 | public class CustomViewLight: UIView { 13 | 14 | public var view:UIView? 15 | 16 | override public init(frame: CGRect) { 17 | super.init(frame: frame) 18 | setup() 19 | } 20 | 21 | required public init(coder : NSCoder) { 22 | super.init(coder:coder) 23 | setup() 24 | } 25 | 26 | public func setup(){ 27 | instantiateWithXib() 28 | } 29 | 30 | deinit{ 31 | view = nil 32 | } 33 | 34 | } 35 | 36 | protocol CustomViewBundle { 37 | func frameworkBundle() -> NSBundle? 38 | func className() -> String 39 | } 40 | 41 | // MARK: Bundle 42 | extension CustomViewLight: CustomViewBundle { 43 | 44 | public func frameworkBundle() -> NSBundle?{ 45 | return NSBundle(forClass: self.classForCoder) 46 | } 47 | 48 | public func className() -> String{ 49 | return String.className(self.classForCoder) 50 | } 51 | 52 | private func instantiateWithXib(){ 53 | let bundle:NSBundle? = frameworkBundle() 54 | let nibUrl = bundle?.URLForResource(className(), withExtension: "nib") 55 | if bundle == nil || nibUrl == nil { 56 | insertBlankView() 57 | return 58 | } 59 | 60 | var nib:UINib = UINib(nibName: className(), bundle: bundle) 61 | var views = nib.instantiateWithOwner(self, options: nil) 62 | 63 | if count(views) >= 1 { 64 | if let view = views[0] as? UIView { 65 | matchTwoViewsUsingAutolayout(view) 66 | } 67 | } 68 | } 69 | 70 | private func insertBlankView(){ 71 | var view = UIView(frame: CGRectMake(0, 0, 0, 0)) 72 | matchTwoViewsUsingAutolayout(view) 73 | } 74 | 75 | private func matchTwoViewsUsingAutolayout(view:UIView) { 76 | self.view = view 77 | view.backgroundColor = UIColor.clearColor() 78 | view.setTranslatesAutoresizingMaskIntoConstraints(false) 79 | self.addSubview(view) 80 | 81 | self <- view.top == self.top 82 | self <- view.bottom == self.bottom 83 | self <- view.trailing == self.trailing 84 | self <- view.leading == self.leading 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /CustomViewKit/CustomViewSource.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewSource.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/4/8. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class CustomViewSource: CustomViewLight { 12 | 13 | } 14 | 15 | public extension CustomViewSource{ 16 | @IBInspectable public var viewSource:String{ 17 | set{ 18 | if let sources = ViewSourcesInstance.valueForKeyPath(newValue) as? DummyViewSource { 19 | sources.action(self) 20 | } 21 | } 22 | get{ return "" } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CustomViewKit/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.yume190.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CustomViewKit/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 CustomView (yume190@gmail.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /CustomViewKit/Reflect.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Reflect.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/4/8. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | // 9 | //import UIKit 10 | // 11 | //// https://github.com/ksm/SwiftInFlux 12 | //// https://gist.github.com/peebsjs/9288f79322ed3119ece4 13 | //infix operator --> { 14 | // associativity left 15 | //} 16 | // 17 | //public func --> (instance: Any, key: String) -> Any? { 18 | // let mirror = reflect(instance) 19 | // 20 | // for index in 0 ..< mirror.count { 21 | // let (childKey, childMirror) = mirror[index] 22 | // if childKey == key { 23 | // return childMirror.value 24 | // } 25 | // } 26 | // 27 | // return nil 28 | //} 29 | -------------------------------------------------------------------------------- /CustomViewKit/StringExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StringExtension.swift 3 | // SlideMenuControllerSwift 4 | // 5 | // Created by Yuji Hato on 1/22/15. 6 | // Copyright (c) 2015 Yuji Hato. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension String { 12 | static public func className(aClass: AnyClass) -> String { 13 | return NSStringFromClass(aClass).componentsSeparatedByString(".").last! 14 | } 15 | } -------------------------------------------------------------------------------- /CustomViewKit/ViewSources.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewSources.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/4/8. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @objc public protocol ViewSource:class{ 12 | func action(cv:CustomViewLight) 13 | } 14 | 15 | @objc public class ViewSources: NSObject { 16 | 17 | public class var sharedInstance: ViewSources { 18 | dispatch_once(&Inner.token) { 19 | Inner.instance = ViewSources() 20 | } 21 | return Inner.instance! 22 | } 23 | 24 | struct Inner { 25 | static var instance: ViewSources? 26 | static var token: dispatch_once_t = 0 27 | } 28 | 29 | override public func valueForUndefinedKey(key: String) -> AnyObject? { 30 | return nil 31 | } 32 | 33 | } 34 | 35 | public var ViewSourcesInstance: ViewSources { get { return ViewSources.sharedInstance } } 36 | 37 | @objc public class DummyViewSource:ViewSource{ 38 | public func action(cv:CustomViewLight){ 39 | } 40 | } 41 | 42 | @objc public class YumeViewSource:DummyViewSource{ 43 | public typealias SettingClosure = ((T) -> ()) 44 | 45 | private var _settings: SettingClosure 46 | public init(settings:SettingClosure){ 47 | _settings = settings 48 | } 49 | 50 | public override func action(cv:CustomViewLight){ 51 | if let _view = cv as? T { 52 | _settings(_view) 53 | 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /CustomViewKit/ViewStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewStyle.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/3/15. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public var ViewStyleInstance: ViewStyles { get { return ViewStyles.sharedInstance } } 12 | 13 | @objc public class ViewStyle{ 14 | public var borderColor:UIColor? 15 | public var borderWidth:CGFloat? 16 | public var cornerRadius:CGFloat? 17 | public var shadowColor:UIColor? 18 | public var shadowRadius:CGFloat? 19 | public var shadowOpacity:Float? 20 | public var shadowOffsetY:CGFloat? 21 | 22 | public init(){} 23 | 24 | public func set(#borderColor:UIColor) -> ViewStyle{ 25 | self.borderColor = borderColor 26 | return self 27 | } 28 | 29 | public func set(#borderWidth:CGFloat) -> ViewStyle{ 30 | self.borderWidth = borderWidth 31 | return self 32 | } 33 | 34 | public func set(#cornorRadius:CGFloat) -> ViewStyle{ 35 | self.cornerRadius = cornorRadius 36 | return self 37 | } 38 | 39 | public func set(#shadowColor:UIColor) -> ViewStyle{ 40 | self.shadowColor = shadowColor 41 | return self 42 | } 43 | 44 | public func set(#shadowRadius:CGFloat) -> ViewStyle{ 45 | self.shadowRadius = shadowRadius 46 | return self 47 | } 48 | 49 | public func set(#shadowOpacity:Float) -> ViewStyle{ 50 | self.shadowOpacity = shadowOpacity 51 | return self 52 | } 53 | 54 | public func set(#shadowOffsetY:CGFloat) -> ViewStyle{ 55 | self.shadowOffsetY = shadowOffsetY 56 | return self 57 | } 58 | 59 | } 60 | 61 | public class ViewStyles: NSObject { 62 | 63 | public class var sharedInstance: ViewStyles { 64 | dispatch_once(&Inner.token) { 65 | Inner.instance = ViewStyles() 66 | } 67 | return Inner.instance! 68 | } 69 | 70 | struct Inner { 71 | static var instance: ViewStyles? 72 | static var token: dispatch_once_t = 0 73 | } 74 | 75 | public func none() -> ViewStyle{ 76 | return ViewStyle().set(borderColor: UIColor.clearColor()) 77 | .set(borderWidth:0) 78 | .set(cornorRadius:0) 79 | .set(shadowColor:UIColor.clearColor()) 80 | .set(shadowRadius:0) 81 | .set(shadowOpacity:0) 82 | .set(shadowOffsetY:0) 83 | } 84 | 85 | public func fb() -> ViewStyle{ 86 | return ViewStyle().set(borderWidth:10).set(borderColor:UIColor.blueColor()).set(cornorRadius:20) 87 | } 88 | 89 | public func yume() -> ViewStyle{ 90 | return ViewStyle().set(borderWidth:3).set(borderColor:UIColor.purpleColor()).set(cornorRadius:30) 91 | } 92 | 93 | override public func valueForUndefinedKey(key: String) -> AnyObject? { 94 | return none() 95 | } 96 | 97 | } -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // PodTest 4 | // 5 | // Created by Yume on 2015/3/22. 6 | // Copyright (c) 2015年 Yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest/CV1.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CV1.swift 3 | // PodTest 4 | // 5 | // Created by Yume on 2015/3/22. 6 | // Copyright (c) 2015年 Yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CustomView 11 | 12 | class CV1: CustomViewLayerStyle { 13 | 14 | var label1:UILabel! 15 | 16 | override func setup() { 17 | super.setup() 18 | label1 = UILabel(frame: CGRectMake(0, 0, 100, 100)) 19 | label1.text="1000" 20 | self.view?.addSubview(label1) 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest/CV2.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CV2.swift 3 | // PodTest 4 | // 5 | // Created by Yume on 2015/3/22. 6 | // Copyright (c) 2015年 Yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CustomView 11 | 12 | class CV2: CustomViewLayerStyle { 13 | @IBOutlet weak var label1: UILabel! 14 | @IBOutlet weak var label2: UILabel! 15 | @IBOutlet weak var label3: UILabel! 16 | } 17 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest/CV2.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 31 | 37 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest/CustomViewKitExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewC.swift 3 | // PodTest 4 | // 5 | // Created by Yume on 2015/3/22. 6 | // Copyright (c) 2015年 Yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CustomView 11 | 12 | extension CustomViewLight{ 13 | public func bundleIdentifier() -> String{ 14 | //Bundle Identifier can be find at Target -> Your Framework -> Bundle Identifier 15 | return "com.yume190.PodTest" 16 | } 17 | } 18 | 19 | 20 | extension ViewStyles { 21 | 22 | public func customStyle1() -> ViewStyle{ 23 | return ViewStyle().set(borderWidth:20).set(borderColor:UIColor.darkGrayColor()).set(cornorRadius:20) 24 | } 25 | 26 | public func customStyle2() -> ViewStyle{ 27 | return ViewStyle().set(borderWidth:30).set(borderColor:UIColor.greenColor()).set(cornorRadius:30) 28 | } 29 | } 30 | 31 | extension ViewSources { 32 | 33 | public func cv1Source1() -> ViewSource{ 34 | return YumeViewSource(){ 35 | (CV1) -> () in 36 | CV1.label1.text = "100" 37 | } 38 | } 39 | 40 | public func cv1Source2() -> ViewSource{ 41 | return YumeViewSource(){ 42 | (CV1) -> () in 43 | CV1.label1.text = "2000" 44 | } 45 | } 46 | 47 | public var cv2Source1:ViewSource 48 | { 49 | get { 50 | return YumeViewSource(){ 51 | (CV2) -> () in 52 | CV2.label1.text = "11111" 53 | CV2.label2.text = "22222" 54 | CV2.label3.text = "33333" 55 | } 56 | } 57 | } 58 | 59 | public func cv2Source2() -> ViewSource{ 60 | return YumeViewSource(){ 61 | (CV2) -> () in 62 | CV2.label1.text = "abc" 63 | CV2.label2.text = "123" 64 | CV2.label3.text = "xyz" 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.yume190.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTest/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // PodTest 4 | // 5 | // Created by Yume on 2015/3/22. 6 | // Copyright (c) 2015年 Yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | var cv1 = CV1(frame:CGRectMake(0, 0, 100, 100)) 17 | cv1.backgroundColor = UIColor.brownColor() 18 | self.view.addSubview(cv1) 19 | 20 | var cv2 = CV2(frame:CGRectMake(0, 100, 150, 175)) 21 | cv2.style = "yume" 22 | cv2.viewSource = "cv2Source1" 23 | self.view.addSubview(cv2) 24 | 25 | // Do any additional setup after loading the view, typically from a nib. 26 | } 27 | 28 | override func didReceiveMemoryWarning() { 29 | super.didReceiveMemoryWarning() 30 | // Dispose of any resources that can be recreated. 31 | } 32 | 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTestTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.yume190.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /CustomViewKitExample/PodTestTests/PodTestTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PodTestTests.swift 3 | // PodTestTests 4 | // 5 | // Created by Yume on 2015/3/22. 6 | // Copyright (c) 2015年 Yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class PodTestTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /CustomViewKitExample/Podfile: -------------------------------------------------------------------------------- 1 | #source 'https://github.com/CocoaPods/Specs.git' 2 | 3 | platform :ios, '8.0' 4 | use_frameworks! 5 | pod 'CustomView', '~> 1.3' 6 | #pod 'CustomViewKit', :git => 'https://github.com/yume190/CustomView.git', :tag => '1.0' -------------------------------------------------------------------------------- /CustomViewKitExample/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - CustomView (1.3) 3 | 4 | DEPENDENCIES: 5 | - CustomView (~> 1.3) 6 | 7 | SPEC CHECKSUMS: 8 | CustomView: c6ef1dce9b12452ed07a8c50026965a76bbb8742 9 | 10 | COCOAPODS: 0.36.3 11 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/CustomViewKit/AutoLayoutExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AutoLayoutExtension.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/3/14. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public struct LayoutAttribute { 12 | public var view:UIView? 13 | public var attribute:NSLayoutAttribute 14 | public var multiplier:CGFloat 15 | public var constant:CGFloat 16 | 17 | init(view:UIView, attribute: NSLayoutAttribute, constant:CGFloat = 0, multiplier:CGFloat = 1.0){ 18 | self.view = view; 19 | self.attribute = attribute 20 | self.multiplier = multiplier 21 | self.constant = constant; 22 | } 23 | 24 | } 25 | 26 | public extension UIView { 27 | 28 | func addConstraints (constraints: NSLayoutConstraint...){ 29 | for constraint in constraints { 30 | self.addConstraint(constraint) 31 | } 32 | } 33 | 34 | public var width : LayoutAttribute { 35 | get { return LayoutAttribute(view: self, attribute : .Width); } 36 | } 37 | 38 | public var height : LayoutAttribute { 39 | get { return LayoutAttribute(view: self, attribute : .Height); } 40 | } 41 | 42 | public var leading : LayoutAttribute { 43 | get { return LayoutAttribute(view: self, attribute : .Leading); } 44 | } 45 | 46 | public var trailing : LayoutAttribute { 47 | get { return LayoutAttribute(view: self, attribute : .Trailing); } 48 | } 49 | 50 | public var top : LayoutAttribute { 51 | get { return LayoutAttribute(view: self, attribute : .Top); } 52 | } 53 | 54 | public var bottom : LayoutAttribute { 55 | get { return LayoutAttribute(view: self, attribute : .Bottom); } 56 | } 57 | 58 | public var centerX : LayoutAttribute { 59 | get { return LayoutAttribute(view: self, attribute : .CenterX); } 60 | } 61 | 62 | public var centerY : LayoutAttribute { 63 | get { return LayoutAttribute(view: self, attribute : .CenterY); } 64 | } 65 | 66 | } 67 | 68 | public func == (left: LayoutAttribute, right: LayoutAttribute) -> NSLayoutConstraint { 69 | var layoutConstraint = NSLayoutConstraint(item:left.view!, 70 | attribute: left.attribute, relatedBy: NSLayoutRelation.Equal, toItem: right.view, 71 | attribute: right.attribute, multiplier: right.multiplier, constant: right.constant) 72 | 73 | return layoutConstraint 74 | } 75 | 76 | public func >= (left: LayoutAttribute, right: LayoutAttribute) -> NSLayoutConstraint { 77 | var layoutConstraint = NSLayoutConstraint(item: left.view!, 78 | attribute: left.attribute, relatedBy: NSLayoutRelation.GreaterThanOrEqual, toItem: right.view, attribute: right.attribute, 79 | multiplier: right.multiplier, constant: right.constant); 80 | return layoutConstraint 81 | } 82 | 83 | public func <= (left: LayoutAttribute, right: LayoutAttribute) -> NSLayoutConstraint { 84 | var layoutConstraint = NSLayoutConstraint(item: left.view!, 85 | attribute: left.attribute, relatedBy: NSLayoutRelation.LessThanOrEqual, toItem: right.view, attribute: right.attribute, 86 | multiplier: right.multiplier, constant: right.constant); 87 | return layoutConstraint 88 | } 89 | 90 | public func == (left: LayoutAttribute, right: CGFloat) -> NSLayoutConstraint { 91 | var layoutConstraint = NSLayoutConstraint(item:left.view!, 92 | attribute: left.attribute, relatedBy: NSLayoutRelation.Equal, toItem: nil, 93 | attribute: .NotAnAttribute, multiplier: 1.0, constant: right) 94 | 95 | return layoutConstraint 96 | } 97 | 98 | public func <= (left: LayoutAttribute, right: CGFloat) -> NSLayoutConstraint { 99 | var layoutConstraint = NSLayoutConstraint(item:left.view!, 100 | attribute: left.attribute, relatedBy: NSLayoutRelation.LessThanOrEqual, toItem: nil, 101 | attribute: .NotAnAttribute, multiplier: 1.0, constant: right) 102 | 103 | return layoutConstraint 104 | } 105 | 106 | public func >= (left: LayoutAttribute, right: CGFloat) -> NSLayoutConstraint { 107 | var layoutConstraint = NSLayoutConstraint(item:left.view!, 108 | attribute: left.attribute, relatedBy: NSLayoutRelation.GreaterThanOrEqual, toItem: nil, 109 | attribute: .NotAnAttribute, multiplier: 1.0, constant: right) 110 | 111 | return layoutConstraint 112 | } 113 | 114 | // ------------------------------------------ 115 | 116 | infix operator *+ { 117 | associativity left 118 | precedence 150 119 | } 120 | 121 | public func *+(left: LayoutAttribute, right: (multiplier:CGFloat, contant:CGFloat)) -> LayoutAttribute { 122 | var layoutAttribute = LayoutAttribute(view:left.view!, attribute: left.attribute, constant: right.contant, multiplier:right.multiplier) 123 | return layoutAttribute 124 | } 125 | 126 | public func *(left: LayoutAttribute, right: CGFloat) -> LayoutAttribute { 127 | var layoutAttribute = LayoutAttribute(view:left.view!, attribute: left.attribute, constant: 0, multiplier:right) 128 | return layoutAttribute 129 | } 130 | 131 | public func +(left: LayoutAttribute, right: CGFloat) -> LayoutAttribute { 132 | var layoutAttribute = LayoutAttribute(view:left.view!, attribute: left.attribute, constant: right, multiplier:left.multiplier) 133 | return layoutAttribute 134 | } 135 | 136 | public func -(left: LayoutAttribute, right: CGFloat) -> LayoutAttribute { 137 | var layoutAttribute = LayoutAttribute(view:left.view!, attribute: left.attribute, constant: -right, multiplier:left.multiplier) 138 | return layoutAttribute 139 | } 140 | 141 | infix operator <~ { 142 | associativity left 143 | precedence 125 144 | } 145 | 146 | public func <~ (left: NSLayoutConstraint, right: UILayoutPriority) -> NSLayoutConstraint { 147 | left.priority = right 148 | return left 149 | } 150 | 151 | infix operator <- { 152 | associativity right 153 | precedence 90 154 | } 155 | 156 | public func <- (left: UIView, right: NSLayoutConstraint) -> UIView { 157 | left.addConstraint(right) 158 | return left 159 | } 160 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/CustomViewKit/CustomViewLayer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomView2.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/3/20. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @IBDesignable 12 | public class CustomViewLayer: CustomViewSource { 13 | 14 | @IBInspectable public var borderColor: UIColor? { 15 | didSet { 16 | if let color = borderColor { 17 | layer.borderColor = color.CGColor 18 | } 19 | } 20 | } 21 | @IBInspectable public var borderWidth: CGFloat = CGFloat.infinity { didSet { layer.borderWidth = borderWidth }} 22 | 23 | @IBInspectable public var cornerRadius: CGFloat = CGFloat.infinity { didSet { layer.cornerRadius = cornerRadius }} 24 | 25 | @IBInspectable public var shadowColor: UIColor? { 26 | didSet { 27 | if let color = shadowColor{ 28 | layer.shadowColor = color.CGColor 29 | } 30 | } 31 | } 32 | @IBInspectable public var shadowRadius: CGFloat = CGFloat.infinity { didSet { layer.shadowRadius = shadowRadius }} 33 | @IBInspectable public var shadowOpacity: Float = Float.infinity { didSet { layer.shadowOpacity = shadowOpacity }} 34 | @IBInspectable public var shadowOffsetY: CGFloat = CGFloat.infinity { didSet { layer.shadowOffset.height = shadowOffsetY }} 35 | 36 | } 37 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/CustomViewKit/CustomViewLayerStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomView2.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/3/20. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @IBDesignable 12 | public class CustomViewLayerStyle: CustomViewLayer { 13 | 14 | @IBInspectable public var style:String = "none" { 15 | didSet{ 16 | if let _style = ViewStyleInstance.valueForKey(style) as? ViewStyle { 17 | _viewStyle = _style 18 | } 19 | } 20 | } 21 | 22 | } 23 | 24 | // MARK: Style 25 | public extension CustomViewLayerStyle { 26 | private func setViewStyle(vStyle:ViewStyle){ 27 | println("set style") 28 | 29 | if let _borderColor = borderColor?.CGColor ?? vStyle.borderColor?.CGColor { 30 | layer.borderColor = _borderColor 31 | } 32 | 33 | if let _borderWidth = borderWidth != CGFloat.infinity ? borderWidth : vStyle.borderWidth { 34 | layer.borderWidth = _borderWidth 35 | } 36 | 37 | if let _cornerRadius = cornerRadius != CGFloat.infinity ? cornerRadius : vStyle.cornerRadius { 38 | layer.cornerRadius = _cornerRadius 39 | } 40 | 41 | if let _shadowRadius = shadowRadius != CGFloat.infinity ? shadowRadius : vStyle.shadowRadius{ 42 | layer.shadowRadius = _shadowRadius 43 | } 44 | 45 | if let _shadowColor = shadowColor?.CGColor ?? vStyle.shadowColor?.CGColor{ 46 | layer.shadowColor = _shadowColor 47 | } 48 | 49 | if let _shadowOpacity = shadowOpacity != Float.infinity ? shadowOpacity: vStyle.shadowOpacity{ 50 | layer.shadowOpacity = _shadowOpacity 51 | } 52 | 53 | if let _shadowOffsetY = shadowOffsetY != CGFloat.infinity ? shadowOffsetY : vStyle.shadowOffsetY{ 54 | layer.shadowOffset.height = _shadowOffsetY 55 | } 56 | } 57 | 58 | private var _viewStyle:ViewStyle{ 59 | set{ setViewStyle(newValue) } 60 | get{ return ViewStyleInstance.none() } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/CustomViewKit/CustomViewLight.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomView2.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/3/20. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @IBDesignable 12 | public class CustomViewLight: UIView { 13 | 14 | public var view:UIView? 15 | 16 | override public init(frame: CGRect) { 17 | super.init(frame: frame) 18 | setup() 19 | } 20 | 21 | required public init(coder : NSCoder) { 22 | super.init(coder:coder) 23 | setup() 24 | } 25 | 26 | public func setup(){ 27 | instantiateWithXib() 28 | } 29 | 30 | deinit{ 31 | view = nil 32 | } 33 | 34 | } 35 | 36 | protocol CustomViewBundle { 37 | func frameworkBundle() -> NSBundle? 38 | func bundleIdentifier() -> String 39 | func className() -> String 40 | } 41 | 42 | // MARK: Bundle 43 | extension CustomViewLight: CustomViewBundle { 44 | 45 | public func frameworkBundle() -> NSBundle?{ 46 | return NSBundle(identifier: bundleIdentifier()) 47 | } 48 | 49 | public func bundleIdentifier() -> String{ 50 | //Bundle Identifier can be find at Target -> Your Framework -> Bundle Identifier 51 | return NSBundle.mainBundle().bundleIdentifier ?? "com.yume190.CustomViewSwift" 52 | } 53 | 54 | public func className() -> String{ 55 | return String.className(self.classForCoder) 56 | } 57 | 58 | private func instantiateWithXib(){ 59 | let bundle:NSBundle? = frameworkBundle() 60 | let nibUrl = bundle?.URLForResource(className(), withExtension: "nib") 61 | if bundle == nil || nibUrl == nil { 62 | insertBlankView() 63 | return 64 | } 65 | 66 | var nib:UINib = UINib(nibName: className(), bundle: bundle) 67 | var views = nib.instantiateWithOwner(self, options: nil) 68 | 69 | if count(views) >= 1 { 70 | if let view = views[0] as? UIView { 71 | matchTwoViewsUsingAutolayout(view) 72 | } 73 | } 74 | } 75 | 76 | private func insertBlankView(){ 77 | var view = UIView(frame: CGRectMake(0, 0, 0, 0)) 78 | matchTwoViewsUsingAutolayout(view) 79 | } 80 | 81 | private func matchTwoViewsUsingAutolayout(view:UIView) { 82 | self.view = view 83 | view.backgroundColor = UIColor.clearColor() 84 | view.setTranslatesAutoresizingMaskIntoConstraints(false) 85 | self.addSubview(view) 86 | 87 | self <- view.top == self.top 88 | self <- view.bottom == self.bottom 89 | self <- view.trailing == self.trailing 90 | self <- view.leading == self.leading 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/CustomViewKit/CustomViewSource.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewSource.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/4/8. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class CustomViewSource: CustomViewLight { 12 | 13 | } 14 | 15 | public extension CustomViewSource{ 16 | @IBInspectable public var viewSource:String{ 17 | set{ 18 | if let sources = ViewSourcesInstance.valueForKeyPath(newValue) as? DummyViewSource { 19 | sources.action(self) 20 | } 21 | } 22 | get{ return "" } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/CustomViewKit/Reflect.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Reflect.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/4/8. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | // 9 | //import UIKit 10 | // 11 | //// https://github.com/ksm/SwiftInFlux 12 | //// https://gist.github.com/peebsjs/9288f79322ed3119ece4 13 | //infix operator --> { 14 | // associativity left 15 | //} 16 | // 17 | //public func --> (instance: Any, key: String) -> Any? { 18 | // let mirror = reflect(instance) 19 | // 20 | // for index in 0 ..< mirror.count { 21 | // let (childKey, childMirror) = mirror[index] 22 | // if childKey == key { 23 | // return childMirror.value 24 | // } 25 | // } 26 | // 27 | // return nil 28 | //} 29 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/CustomViewKit/StringExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StringExtension.swift 3 | // SlideMenuControllerSwift 4 | // 5 | // Created by Yuji Hato on 1/22/15. 6 | // Copyright (c) 2015 Yuji Hato. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension String { 12 | static public func className(aClass: AnyClass) -> String { 13 | return NSStringFromClass(aClass).componentsSeparatedByString(".").last! 14 | } 15 | } -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/CustomViewKit/ViewSources.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewSources.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/4/8. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @objc public protocol ViewSource:class{ 12 | func action(cv:CustomViewLight) 13 | } 14 | 15 | @objc public class ViewSources: NSObject { 16 | 17 | public class var sharedInstance: ViewSources { 18 | dispatch_once(&Inner.token) { 19 | Inner.instance = ViewSources() 20 | } 21 | return Inner.instance! 22 | } 23 | 24 | struct Inner { 25 | static var instance: ViewSources? 26 | static var token: dispatch_once_t = 0 27 | } 28 | 29 | override public func valueForUndefinedKey(key: String) -> AnyObject? { 30 | return nil 31 | } 32 | 33 | } 34 | 35 | public var ViewSourcesInstance: ViewSources { get { return ViewSources.sharedInstance } } 36 | 37 | @objc public class DummyViewSource:ViewSource{ 38 | public func action(cv:CustomViewLight){ 39 | } 40 | } 41 | 42 | @objc public class YumeViewSource:DummyViewSource{ 43 | public typealias SettingClosure = ((T) -> ()) 44 | 45 | private var _settings: SettingClosure 46 | public init(settings:SettingClosure){ 47 | _settings = settings 48 | } 49 | 50 | public override func action(cv:CustomViewLight){ 51 | if let _view = cv as? T { 52 | _settings(_view) 53 | 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/CustomViewKit/ViewStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewStyle.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2015/3/15. 6 | // Copyright (c) 2015年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public var ViewStyleInstance: ViewStyles { get { return ViewStyles.sharedInstance } } 12 | 13 | @objc public class ViewStyle{ 14 | public var borderColor:UIColor? 15 | public var borderWidth:CGFloat? 16 | public var cornerRadius:CGFloat? 17 | public var shadowColor:UIColor? 18 | public var shadowRadius:CGFloat? 19 | public var shadowOpacity:Float? 20 | public var shadowOffsetY:CGFloat? 21 | 22 | public init(){} 23 | 24 | public func set(#borderColor:UIColor) -> ViewStyle{ 25 | self.borderColor = borderColor 26 | return self 27 | } 28 | 29 | public func set(#borderWidth:CGFloat) -> ViewStyle{ 30 | self.borderWidth = borderWidth 31 | return self 32 | } 33 | 34 | public func set(#cornorRadius:CGFloat) -> ViewStyle{ 35 | self.cornerRadius = cornorRadius 36 | return self 37 | } 38 | 39 | public func set(#shadowColor:UIColor) -> ViewStyle{ 40 | self.shadowColor = shadowColor 41 | return self 42 | } 43 | 44 | public func set(#shadowRadius:CGFloat) -> ViewStyle{ 45 | self.shadowRadius = shadowRadius 46 | return self 47 | } 48 | 49 | public func set(#shadowOpacity:Float) -> ViewStyle{ 50 | self.shadowOpacity = shadowOpacity 51 | return self 52 | } 53 | 54 | public func set(#shadowOffsetY:CGFloat) -> ViewStyle{ 55 | self.shadowOffsetY = shadowOffsetY 56 | return self 57 | } 58 | 59 | } 60 | 61 | public class ViewStyles: NSObject { 62 | 63 | public class var sharedInstance: ViewStyles { 64 | dispatch_once(&Inner.token) { 65 | Inner.instance = ViewStyles() 66 | } 67 | return Inner.instance! 68 | } 69 | 70 | struct Inner { 71 | static var instance: ViewStyles? 72 | static var token: dispatch_once_t = 0 73 | } 74 | 75 | public func none() -> ViewStyle{ 76 | return ViewStyle().set(borderColor: UIColor.clearColor()) 77 | .set(borderWidth:0) 78 | .set(cornorRadius:0) 79 | .set(shadowColor:UIColor.clearColor()) 80 | .set(shadowRadius:0) 81 | .set(shadowOpacity:0) 82 | .set(shadowOffsetY:0) 83 | } 84 | 85 | public func fb() -> ViewStyle{ 86 | return ViewStyle().set(borderWidth:10).set(borderColor:UIColor.blueColor()).set(cornorRadius:20) 87 | } 88 | 89 | public func yume() -> ViewStyle{ 90 | return ViewStyle().set(borderWidth:3).set(borderColor:UIColor.purpleColor()).set(cornorRadius:30) 91 | } 92 | 93 | override public func valueForUndefinedKey(key: String) -> AnyObject? { 94 | return none() 95 | } 96 | 97 | } -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 CustomView (yume190@gmail.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/CustomView/README.md: -------------------------------------------------------------------------------- 1 | CustomView 2 | ========== 3 | 4 | IOS Custom View with xib(IOS 7 & 8) and Live Render (IOS 8) 5 | 6 | * [Custom View With xib (IOS 7 & 8)](CustomView.md) 7 | * [Live Render (IOS 8)](LiveRender.md) 8 | * [Key Value Coding](KVC.md) 9 | * [Custom View with Xib + Live Render + KVC](CustomView_LiveRender_KVC.md) 10 | * WWDC 2014 Session 401 11 | * [Debug Selected Views](WWDC_2014_Session_401.md/#debugSelectedViews) 12 | * [Debug View Hierarchy](WWDC_2014_Session_401.md/#debugViewHierarchy) 13 | 14 | --- 15 | 16 | # CustomViewKit 17 | 18 | ### Manual Install 19 | 20 | You can download this repo and drag `CustomViewKit` to your project. 21 | 22 | then find the swift file `CustomViewLight.swift`, and replace `bundleIdentifier return value` to your bundleIdentifier 23 | 24 | ### Install with cocoapod 25 | 26 | Add a Podfile at your project 27 | 28 | touch Podfile 29 | 30 | Add CustomViewKit pod 31 | 32 | ``` 33 | platform :ios, '8.0' 34 | use_frameworks! 35 | pod 'CustomView', '~> 1.1' 36 | ``` 37 | 38 | then create a swift file `CustomViewKitExtension.swift`, and override `bundleIdentifier` method 39 | 40 | ``` 41 | import UIKit 42 | import CustomView 43 | 44 | extension CustomViewLight{ 45 | public func bundleIdentifier() -> String{ 46 | //Bundle Identifier can be find at Target -> Your Framework -> Bundle Identifier 47 | return "com.yume190.PodTest" 48 | } 49 | } 50 | ``` 51 | 52 | ### Usage 53 | 54 | ##### Only code 55 | 56 | Override `setup` method and add your custom code 57 | 58 | ``` 59 | import UIKit 60 | import CustomView 61 | 62 | class CV1: CustomViewLight { 63 | 64 | override func setup() { 65 | super.setup() 66 | // custom code 67 | var c = UILabel(frame: CGRectMake(0, 0, 100, 100)) 68 | c.text="1000" 69 | self.view?.addSubview(c) 70 | } 71 | 72 | } 73 | ``` 74 | 75 | ##### With xib 76 | 77 | Create swift file and xib file with same name 78 | 79 | * CV2.swift 80 | * CV2.xib 81 | 82 | ``` 83 | import UIKit 84 | import CustomView 85 | 86 | class CV2: CustomViewLayerStyle { 87 | @IBOutlet weak var label1: UILabel! 88 | @IBOutlet weak var label2: UILabel! 89 | @IBOutlet weak var label3: UILabel! 90 | } 91 | ``` 92 | 93 | Set `File's Owner` for your xib 94 | 95 | ![File's Owner](/images/i5.png) 96 | 97 | ### Custom Style 98 | 99 | ##### Add your custom style 100 | 101 | ``` 102 | extension ViewStyles { 103 | 104 | public func customStyle1() -> ViewStyle{ 105 | return ViewStyle().set(borderWidth:20).set(borderColor:UIColor.darkGrayColor()).set(cornorRadius:20) 106 | } 107 | 108 | public func customStyle2() -> ViewStyle{ 109 | return ViewStyle().set(borderWidth:30).set(borderColor:UIColor.greenColor()).set(cornorRadius:30) 110 | } 111 | } 112 | ``` 113 | 114 | ##### Use your custom style 115 | 116 | Set style by string`(method name)`, and `CustomViewLayerStyle` will find the method with KVC(Key Value Coding). 117 | 118 | ``` 119 | var cv2 = CV2(frame:CGRectMake(0, 100, 150, 150)) 120 | cv2.style = "customStyle1" 121 | ``` 122 | 123 | ### Custom View Source 124 | 125 | ##### Add your custom view source 126 | 127 | > NOTE : return type must be `ViewSource` 128 | 129 | ``` 130 | extension ViewSources { 131 | 132 | public var cv2Source1:ViewSource 133 | { 134 | get { 135 | return YumeViewSource(){ 136 | (CV2) -> () in 137 | CV2.label1.text = "11111" 138 | CV2.label2.text = "22222" 139 | CV2.label3.text = "33333" 140 | } 141 | } 142 | } 143 | 144 | public func cv2Source2() -> ViewSource{ 145 | return YumeViewSource(){ 146 | (CV2) -> () in 147 | CV2.label1.text = "abc" 148 | CV2.label2.text = "123" 149 | CV2.label3.text = "xyz" 150 | } 151 | } 152 | } 153 | ``` 154 | 155 | ##### Use your custom view source 156 | 157 | ``` 158 | var cv2 = CV2(frame:CGRectMake(0, 100, 150, 150)) 159 | cv2.viewSource = "cv2Source1" 160 | ``` -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - CustomView (1.3) 3 | 4 | DEPENDENCIES: 5 | - CustomView (~> 1.3) 6 | 7 | SPEC CHECKSUMS: 8 | CustomView: c6ef1dce9b12452ed07a8c50026965a76bbb8742 9 | 10 | COCOAPODS: 0.36.3 11 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods-CustomView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.3 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods-CustomView/Pods-CustomView-Private.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Pods-CustomView.xcconfig" 2 | CONFIGURATION_BUILD_DIR = $PODS_FRAMEWORK_BUILD_PATH 3 | FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH" 4 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 5 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/CustomView" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/CustomView" 6 | OTHER_LDFLAGS = -ObjC 7 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 8 | PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods 9 | PODS_ROOT = ${SRCROOT} 10 | SKIP_INSTALL = YES -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods-CustomView/Pods-CustomView-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_CustomView : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_CustomView 5 | @end 6 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods-CustomView/Pods-CustomView-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | 5 | #import "Pods-environment.h" 6 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods-CustomView/Pods-CustomView-umbrella.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | FOUNDATION_EXPORT double CustomViewVersionNumber; 5 | FOUNDATION_EXPORT const unsigned char CustomViewVersionString[]; 6 | 7 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods-CustomView/Pods-CustomView.modulemap: -------------------------------------------------------------------------------- 1 | framework module CustomView { 2 | umbrella header "Pods-CustomView-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods-CustomView/Pods-CustomView.xcconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yume190/CustomView/3847470236e8527bc29f66975cbda12f2ba4b8e8/CustomViewKitExample/Pods/Target Support Files/Pods-CustomView/Pods-CustomView.xcconfig -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Pods-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | 4 | ## CustomView 5 | 6 | Copyright (c) 2014 CustomView (yume190@gmail.com) 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | Generated by CocoaPods - http://cocoapods.org 26 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Pods-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Copyright (c) 2014 CustomView (yume190@gmail.com) 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in 27 | all copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35 | THE SOFTWARE. 36 | Title 37 | CustomView 38 | Type 39 | PSGroupSpecifier 40 | 41 | 42 | FooterText 43 | Generated by CocoaPods - http://cocoapods.org 44 | Title 45 | 46 | Type 47 | PSGroupSpecifier 48 | 49 | 50 | StringsTable 51 | Acknowledgements 52 | Title 53 | Acknowledgements 54 | 55 | 56 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Pods-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods : NSObject 3 | @end 4 | @implementation PodsDummy_Pods 5 | @end 6 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Pods-environment.h: -------------------------------------------------------------------------------- 1 | 2 | // To check if a library is compiled with CocoaPods you 3 | // can use the `COCOAPODS` macro definition which is 4 | // defined in the xcconfigs so it is available in 5 | // headers also when they are imported in the client 6 | // project. 7 | 8 | 9 | // CustomView 10 | #define COCOAPODS_POD_AVAILABLE_CustomView 11 | #define COCOAPODS_VERSION_MAJOR_CustomView 1 12 | #define COCOAPODS_VERSION_MINOR_CustomView 3 13 | #define COCOAPODS_VERSION_PATCH_CustomView 0 14 | 15 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Pods-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 5 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 6 | 7 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 8 | 9 | install_framework() 10 | { 11 | local source="${BUILT_PRODUCTS_DIR}/Pods/$1" 12 | local destination="${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 13 | 14 | if [ -L "${source}" ]; then 15 | echo "Symlinked..." 16 | source=$(readlink "${source}") 17 | fi 18 | 19 | # use filter instead of exclude so missing patterns dont' throw errors 20 | echo "rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers/" --filter "- PrivateHeaders/" ${source} ${destination}" 21 | rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers/" --filter "- PrivateHeaders/" "${source}" "${destination}" 22 | # Resign the code if required by the build settings to avoid unstable apps 23 | if [ "${CODE_SIGNING_REQUIRED}" == "YES" ]; then 24 | code_sign "${destination}/$1" 25 | fi 26 | 27 | # Embed linked Swift runtime libraries 28 | local basename 29 | basename=$(echo $1 | sed -E s/\\..+// && exit ${PIPESTATUS[0]}) 30 | local swift_runtime_libs 31 | swift_runtime_libs=$(xcrun otool -LX "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/$1/${basename}" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) 32 | for lib in $swift_runtime_libs; do 33 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 34 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 35 | if [ "${CODE_SIGNING_REQUIRED}" == "YES" ]; then 36 | code_sign "${destination}/${lib}" 37 | fi 38 | done 39 | } 40 | 41 | # Signs a framework with the provided identity 42 | code_sign() { 43 | # Use the current code_sign_identitiy 44 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 45 | echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements $1" 46 | /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements "$1" 47 | } 48 | 49 | 50 | if [[ "$CONFIGURATION" == "Debug" ]]; then 51 | install_framework 'CustomView.framework' 52 | fi 53 | if [[ "$CONFIGURATION" == "Release" ]]; then 54 | install_framework 'CustomView.framework' 55 | fi 56 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Pods-resources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 5 | 6 | RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt 7 | > "$RESOURCES_TO_COPY" 8 | 9 | XCASSET_FILES="" 10 | 11 | install_resource() 12 | { 13 | case $1 in 14 | *.storyboard) 15 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .storyboard`.storyboardc ${PODS_ROOT}/$1 --sdk ${SDKROOT}" 16 | ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .storyboard`.storyboardc" "${PODS_ROOT}/$1" --sdk "${SDKROOT}" 17 | ;; 18 | *.xib) 19 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .xib`.nib ${PODS_ROOT}/$1 --sdk ${SDKROOT}" 20 | ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .xib`.nib" "${PODS_ROOT}/$1" --sdk "${SDKROOT}" 21 | ;; 22 | *.framework) 23 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 24 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 25 | echo "rsync -av ${PODS_ROOT}/$1 ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 26 | rsync -av "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 27 | ;; 28 | *.xcdatamodel) 29 | echo "xcrun momc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1"`.mom\"" 30 | xcrun momc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodel`.mom" 31 | ;; 32 | *.xcdatamodeld) 33 | echo "xcrun momc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodeld`.momd\"" 34 | xcrun momc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodeld`.momd" 35 | ;; 36 | *.xcmappingmodel) 37 | echo "xcrun mapc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm\"" 38 | xcrun mapc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm" 39 | ;; 40 | *.xcassets) 41 | XCASSET_FILES="$XCASSET_FILES '${PODS_ROOT}/$1'" 42 | ;; 43 | /*) 44 | echo "$1" 45 | echo "$1" >> "$RESOURCES_TO_COPY" 46 | ;; 47 | *) 48 | echo "${PODS_ROOT}/$1" 49 | echo "${PODS_ROOT}/$1" >> "$RESOURCES_TO_COPY" 50 | ;; 51 | esac 52 | } 53 | 54 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 55 | if [[ "${ACTION}" == "install" ]]; then 56 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 57 | fi 58 | rm -f "$RESOURCES_TO_COPY" 59 | 60 | if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] 61 | then 62 | case "${TARGETED_DEVICE_FAMILY}" in 63 | 1,2) 64 | TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" 65 | ;; 66 | 1) 67 | TARGET_DEVICE_ARGS="--target-device iphone" 68 | ;; 69 | 2) 70 | TARGET_DEVICE_ARGS="--target-device ipad" 71 | ;; 72 | *) 73 | TARGET_DEVICE_ARGS="--target-device mac" 74 | ;; 75 | esac 76 | while read line; do XCASSET_FILES="$XCASSET_FILES '$line'"; done <<<$(find "$PWD" -name "*.xcassets" | egrep -v "^$PODS_ROOT") 77 | echo $XCASSET_FILES | xargs actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${IPHONEOS_DEPLOYMENT_TARGET}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 78 | fi 79 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Pods-umbrella.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | FOUNDATION_EXPORT double PodsVersionNumber; 5 | FOUNDATION_EXPORT const unsigned char PodsVersionString[]; 6 | 7 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Pods.debug.xcconfig: -------------------------------------------------------------------------------- 1 | FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH" 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 4 | OTHER_CFLAGS = $(inherited) -iquote "$PODS_FRAMEWORK_BUILD_PATH/CustomView.framework/Headers" 5 | OTHER_LDFLAGS = $(inherited) -ObjC -framework "CustomView" 6 | OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS) 7 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 8 | PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods 9 | PODS_ROOT = ${SRCROOT}/Pods -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Pods.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods { 2 | umbrella header "Pods-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /CustomViewKitExample/Pods/Target Support Files/Pods/Pods.release.xcconfig: -------------------------------------------------------------------------------- 1 | FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH" 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 4 | OTHER_CFLAGS = $(inherited) -iquote "$PODS_FRAMEWORK_BUILD_PATH/CustomView.framework/Headers" 5 | OTHER_LDFLAGS = $(inherited) -ObjC -framework "CustomView" 6 | OTHER_LIBTOOLFLAGS = $(OTHER_LDFLAGS) 7 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 8 | PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods 9 | PODS_ROOT = ${SRCROOT}/Pods -------------------------------------------------------------------------------- /CustomViewObjc/CustomViewObjc-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewObjc-Prefix.pch 3 | // CustomViewTest 4 | // 5 | // Created by APP559 on 2014/7/28. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #ifndef CustomViewTest_CustomViewObjc_Prefix_pch 10 | #define CustomViewTest_CustomViewObjc_Prefix_pch 11 | 12 | // IOS 7 Compliant 13 | // source : http://www.merowing.info/2014/06/behaviours-and-xcode-6/#.U7-hI9OSzEQ 14 | #ifndef IBInspectable 15 | #define IBInspectable 16 | #endif 17 | #ifndef IB_DESIGNABLE 18 | #define IB_DESIGNABLE 19 | #endif 20 | 21 | #define ViewSourceInstance [ViewSource sharedInstance] 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /CustomViewObjc/CustomViewObjc.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewObjc.h 3 | // CustomViewObjc 4 | // 5 | // Created by Yume on 2014/6/3. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for CustomViewObjc. 12 | FOUNDATION_EXPORT double CustomViewObjcVersionNumber; 13 | 14 | //! Project version string for CustomViewObjc. 15 | FOUNDATION_EXPORT const unsigned char CustomViewObjcVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /CustomViewObjc/CustomViewObjetiveC.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewObjetiveC.h 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2014/6/3. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | IB_DESIGNABLE 11 | @interface CustomViewObjetiveC : UIView 12 | 13 | @property (nonatomic) IBInspectable NSInteger lineWidth; 14 | @property (nonatomic) IBInspectable UIColor *fillColor; 15 | @property (nonatomic) IBInspectable UIColor *labelColor; 16 | @property (nonatomic) IBInspectable NSString *labelText; 17 | @property (nonatomic) IBInspectable CGRect labelRect; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /CustomViewObjc/CustomViewObjetiveC.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewObjetiveC.m 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2014/6/3. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import "CustomViewObjetiveC.h" 10 | 11 | @interface CustomViewObjetiveC(){ 12 | dispatch_once_t onceTokenViewLiveRendering; 13 | } 14 | @property (nonatomic,strong) UILabel *label; 15 | @end 16 | 17 | @implementation CustomViewObjetiveC 18 | 19 | - (instancetype)initWithCoder:(NSCoder *)aDecoder{ 20 | self = [super initWithCoder:aDecoder]; 21 | 22 | if (self) { 23 | [self setup]; 24 | } 25 | return self; 26 | } 27 | 28 | - (instancetype)initWithFrame:(CGRect)frame{ 29 | self = [super initWithFrame:frame]; 30 | 31 | if (self) { 32 | [self setup]; 33 | } 34 | return self; 35 | } 36 | 37 | -(void)setup{ 38 | _label = [UILabel new]; 39 | [self addSubview:_label]; 40 | self.backgroundColor = [UIColor whiteColor]; 41 | } 42 | 43 | 44 | -(void)prepareForInterfaceBuilder{ 45 | [self viewLiveRendering]; 46 | } 47 | 48 | /* 49 | // Only override drawRect: if you perform custom drawing. 50 | // An empty implementation adversely affects performance during animation. 51 | */ 52 | - (void)drawRect:(CGRect)rect{ 53 | // Drawing code 54 | CGContextRef context = UIGraphicsGetCurrentContext(); 55 | CGRect myFrame = self.bounds; 56 | 57 | // Set the line width to 10 and inset the rectangle by 58 | // 5 pixels on all sides to compensate for the wider line. 59 | CGContextSetLineWidth(context, _lineWidth); 60 | CGRectInset(myFrame, 5, 5); 61 | 62 | [_fillColor set]; 63 | UIRectFrame(myFrame); 64 | 65 | #ifndef TARGET_INTERFACE_BUILDER 66 | [self viewLiveRendering]; 67 | #endif 68 | } 69 | 70 | -(void)viewLiveRendering{ 71 | dispatch_once(&onceTokenViewLiveRendering, ^{ 72 | _label.frame = _labelRect; 73 | _label.text = _labelText; 74 | _label.textColor = _labelColor; 75 | }); 76 | } 77 | 78 | #pragma mark - Custom Quick Look 79 | 80 | // OS Types Supporting debugQuickLookObject : 81 | // https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/CustomClassDisplay_in_QuickLook/CH02-std_objects_support/CH02-std_objects_support.html#//apple_ref/doc/uid/TP40014001-CH3-SW1 82 | -(id)debugQuickLookObject{ 83 | return self; 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /CustomViewObjc/CustomViewObjetiveC.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /CustomViewObjc/CustomViewTemplate.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewTemplate.h 3 | // 4 | // Created by APP559 on 2014/7/28. 5 | // Copyright (c) 2014年 yume. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @class CustomViewTemplate; 11 | @protocol CustomViewTemplateProtocol 12 | @optional 13 | -(void)setup; 14 | -(void)viewLiveRendering; 15 | 16 | -(void)processViewSource; 17 | -(void)processStoryBoardSource; 18 | -(void)processFuture; 19 | @end 20 | 21 | IB_DESIGNABLE 22 | @interface CustomViewTemplate : UIView 23 | @property (nonatomic) IBInspectable float borderLineWidth; 24 | @property (nonatomic) IBInspectable float borderRadius; 25 | @property (nonatomic) IBInspectable UIColor *borderColor; 26 | 27 | @property (nonatomic) IBInspectable NSString *viewSourceKeyPath; 28 | @property (nonatomic,strong) NSDictionary *viewSourceDictionary; 29 | @end 30 | -------------------------------------------------------------------------------- /CustomViewObjc/CustomViewTemplate.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewTemplate.m 3 | 4 | // 5 | // Created by APP559 on 2014/7/28. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import "CustomViewTemplate.h" 10 | #import "ViewSource.h" 11 | 12 | @implementation CustomViewTemplate 13 | 14 | - (instancetype)initWithCoder:(NSCoder *)aDecoder{ 15 | self = [super initWithCoder:aDecoder]; 16 | 17 | if (self) { 18 | [self setup]; 19 | } 20 | return self; 21 | } 22 | 23 | - (instancetype)initWithFrame:(CGRect)frame{ 24 | self = [super initWithFrame:frame]; 25 | 26 | if (self) { 27 | [self setup]; 28 | } 29 | return self; 30 | } 31 | 32 | - (void) setup{ 33 | NSString *nibName = NSStringFromClass([self class]); 34 | 35 | UINib *nib = [UINib nibWithNibName:nibName bundle:[self frameworkBundle]]; 36 | 37 | [nib instantiateWithOwner:self options:nil]; 38 | } 39 | 40 | -(void)prepareForInterfaceBuilder{ 41 | [self viewLiveRendering]; 42 | } 43 | 44 | 45 | - (void)drawRect:(CGRect)rect{ 46 | #ifndef TARGET_INTERFACE_BUILDER 47 | [self viewLiveRendering]; 48 | #endif 49 | 50 | self.layer.borderColor = _borderColor.CGColor; 51 | self.layer.borderWidth = _borderLineWidth; 52 | 53 | if( [self.layer respondsToSelector:@selector(setCornerRadius:)] ) 54 | [self.layer setCornerRadius:_borderRadius]; 55 | } 56 | 57 | -(void)viewLiveRendering{ 58 | 59 | if ([self respondsToSelector:@selector(processViewSource)]) { 60 | if (_viewSourceKeyPath) { 61 | _viewSourceDictionary = [ViewSourceInstance valueForKey:_viewSourceKeyPath]; 62 | 63 | NSString *type = _viewSourceDictionary[@"type"]; 64 | NSString *className = NSStringFromClass([self class]); 65 | 66 | if ([className isEqualToString:type]) { 67 | [self processViewSource]; 68 | } 69 | } 70 | } 71 | 72 | if ([self respondsToSelector:@selector(processStoryBoardSource)]) { 73 | [self processStoryBoardSource]; 74 | } 75 | 76 | if ([self respondsToSelector:@selector(processFuture)]) { 77 | [self processFuture]; 78 | } 79 | 80 | } 81 | 82 | - (NSBundle *)frameworkBundle{ 83 | return [NSBundle bundleWithIdentifier:[self bundleIdentifier]]; 84 | } 85 | 86 | - (NSString *)bundleIdentifier{ 87 | //Bundle Identifier can be find at Target -> Your Framework -> Bundle Identifier 88 | return @"com.yume190.CustomViewObjc"; 89 | } 90 | 91 | -(id)debugQuickLookObject{ 92 | return self; 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /CustomViewObjc/CustomWithXibLiveRenderKVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomWithXibLiveRenderKVC.h 3 | // CustomViewTest 4 | // 5 | // Created by APP559 on 2014/7/28. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CustomViewTemplate.h" 11 | 12 | IB_DESIGNABLE 13 | @interface CustomWithXibLiveRenderKVC : CustomViewTemplate 14 | @end 15 | -------------------------------------------------------------------------------- /CustomViewObjc/CustomWithXibLiveRenderKVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomWithXibLiveRenderKVC.m 3 | // CustomViewTest 4 | // 5 | // Created by APP559 on 2014/7/28. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import "CustomWithXibLiveRenderKVC.h" 10 | #import "ViewSource.h" 11 | 12 | @interface CustomWithXibLiveRenderKVC() 13 | @property (strong, nonatomic) IBOutlet UIView *view; 14 | @property (weak, nonatomic) IBOutlet UILabel *labelLeft; 15 | @property (weak, nonatomic) IBOutlet UILabel *labelRight; 16 | @property (weak, nonatomic) IBOutlet UIButton *buttonLeft; 17 | @property (weak, nonatomic) IBOutlet UIButton *buttonRight; 18 | @end 19 | 20 | @implementation CustomWithXibLiveRenderKVC 21 | 22 | -(void)setup{ 23 | [super setup]; 24 | [self addSubview:self.view]; 25 | } 26 | 27 | -(void)viewLiveRendering{ 28 | [super viewLiveRendering]; 29 | self.view.backgroundColor = [UIColor clearColor]; 30 | } 31 | 32 | -(void)processViewSource{ 33 | _labelLeft.text = self.viewSourceDictionary[@"labelLeft"]; 34 | _labelRight.text = self.viewSourceDictionary[@"labelRight"]; 35 | [_buttonLeft setTitle:self.viewSourceDictionary[@"buttonLeft"] forState:UIControlStateNormal]; 36 | [_buttonRight setTitle:self.viewSourceDictionary[@"buttonRight"] forState:UIControlStateNormal]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /CustomViewObjc/CustomWithXibLiveRenderKVC.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 27 | 33 | 39 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /CustomViewObjc/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.yume190.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CustomViewObjc/ViewSource.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewSource.h 3 | // CustomViewTest 4 | // 5 | // Created by APP559 on 2014/7/28. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewSource : NSObject 12 | +(ViewSource*) sharedInstance; 13 | @end 14 | -------------------------------------------------------------------------------- /CustomViewObjc/ViewSource.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewSource.m 3 | // CustomViewTest 4 | // 5 | // Created by APP559 on 2014/7/28. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import "ViewSource.h" 10 | 11 | @interface ViewSource (){ 12 | NSString *abc; 13 | } 14 | 15 | @end 16 | 17 | @implementation ViewSource 18 | 19 | +(ViewSource*) sharedInstance{ 20 | static ViewSource *sharedInstance; 21 | static dispatch_once_t onceToken; 22 | 23 | dispatch_once(&onceToken, ^{ 24 | sharedInstance = [ViewSource new]; 25 | }); 26 | 27 | return sharedInstance; 28 | } 29 | 30 | -(NSDictionary*)test1{ 31 | return @{@"type":@"CustomWithXibLiveRenderKVC", 32 | @"labelLeft":@"strong", 33 | @"labelRight":@"r", 34 | @"buttonLeft":@"ll", 35 | @"buttonRight":@"rr"}; 36 | } 37 | 38 | -(NSDictionary*)test2{ 39 | return @{@"type":@"CustomWithXibLiveRenderKVC", 40 | @"labelLeft":@"left", 41 | @"labelRight":@"right", 42 | @"buttonLeft":@"btn left", 43 | @"buttonRight":@"btn right"}; 44 | } 45 | 46 | -(NSDictionary*)test3{ 47 | return @{@"type":@"CustomWithXibLiveRenderKVC", 48 | @"labelLeft":@"左", 49 | @"labelRight":@"右", 50 | @"buttonLeft":@"按鈕左", 51 | @"buttonRight":@"按鈕右"}; 52 | } 53 | @end 54 | -------------------------------------------------------------------------------- /CustomViewObjcTests/CustomViewObjcTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewObjcTests.m 3 | // CustomViewObjcTests 4 | // 5 | // Created by Yume on 2014/6/3. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CustomViewObjcTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CustomViewObjcTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | XCTAssert(YES, @"Pass"); 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /CustomViewObjcTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.yume190.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /CustomViewSwift/CustomViewSwift.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewSwift.h 3 | // CustomViewSwift 4 | // 5 | // Created by Yume on 2014/6/3. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for CustomViewSwift. 12 | FOUNDATION_EXPORT double CustomViewSwiftVersionNumber; 13 | 14 | //! Project version string for CustomViewSwift. 15 | FOUNDATION_EXPORT const unsigned char CustomViewSwiftVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /CustomViewSwift/CustomViewTemplate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewTemplate.swift 3 | // APSMSwift 4 | // 5 | // Created by Yume on 2014/8/3. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol CustomViewTemplateProtocol{ 12 | func setup() 13 | func viewLiveRendering() 14 | 15 | func processViewSource() 16 | func processFuture() 17 | 18 | func className() -> String 19 | } 20 | 21 | protocol CustomViewProtocol:CustomViewTemplateProtocol{ 22 | func instantiateWithXib() 23 | func bundleIdentifier() -> String 24 | func frameworkBundle() -> NSBundle 25 | } 26 | 27 | @IBDesignable 28 | class CustomViewTemplate: UIView ,CustomViewTemplateProtocol{ 29 | 30 | @IBInspectable var viewSourceKeyPath:String? 31 | @IBInspectable var viewSourceDictionary:NSDictionary? 32 | 33 | @IBInspectable var borderLineWidth: CGFloat = 0 { 34 | willSet{ 35 | layer.borderWidth = newValue 36 | } 37 | } 38 | 39 | @IBInspectable var borderRadius: CGFloat = 0 { 40 | willSet{ 41 | layer.cornerRadius = newValue 42 | } 43 | } 44 | 45 | @IBInspectable var borderColor: UIColor = UIColor.clearColor() { 46 | willSet{ 47 | layer.borderColor = newValue.CGColor 48 | } 49 | } 50 | 51 | override init(frame: CGRect) { 52 | super.init(frame: frame) 53 | setup() 54 | } 55 | 56 | required init(coder : NSCoder) { 57 | super.init(coder:coder) 58 | setup() 59 | } 60 | 61 | func setup() {} 62 | 63 | override func prepareForInterfaceBuilder() { 64 | self.viewLiveRendering() 65 | } 66 | 67 | override func drawRect(rect: CGRect) { 68 | self.viewLiveRendering() 69 | } 70 | 71 | func viewLiveRendering() { 72 | if respondsToSelector(Selector("processViewSource")){ 73 | if viewSourceKeyPath != nil{ 74 | viewSourceDictionary = ViewSourceInstance.valueForKeyPath(viewSourceKeyPath!) as? NSDictionary 75 | 76 | let type:NSString? = viewSourceDictionary!["type"] as? NSString 77 | 78 | if type!.isEqualToString(className()) { 79 | processViewSource() 80 | } 81 | } 82 | } 83 | 84 | if respondsToSelector(Selector("processFuture")){ 85 | processFuture() 86 | } 87 | } 88 | 89 | func processViewSource() {} 90 | func processFuture() {} 91 | 92 | func instantiateWithXib(){ 93 | 94 | var bundle:NSBundle = frameworkBundle() 95 | 96 | var nib:UINib = UINib(nibName: className(), bundle: bundle) 97 | 98 | nib.instantiateWithOwner(self, options: nil) 99 | } 100 | 101 | func frameworkBundle() -> NSBundle{ 102 | return NSBundle(identifier: bundleIdentifier())! 103 | } 104 | 105 | func bundleIdentifier() -> String{ 106 | //Bundle Identifier can be find at Target -> Your Framework -> Bundle Identifier 107 | return "com.yume190.CustomViewSwift" 108 | } 109 | 110 | func className() -> String{ 111 | return "" 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /CustomViewSwift/CustomViewWithSwift.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewWithSwift.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2014/6/3. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | @IBDesignable 11 | class CustomViewWithSwift: UIView { 12 | 13 | @IBInspectable var lineWidth: NSInteger 14 | @IBInspectable var fillColor: UIColor 15 | @IBInspectable var labelColor: UIColor 16 | @IBInspectable var labelText: NSString = "" 17 | @IBInspectable var labelRect: CGRect 18 | 19 | override init(frame: CGRect) { 20 | lineWidth = 0 21 | fillColor = UIColor.blackColor() 22 | labelColor = UIColor.blackColor() 23 | labelText = NSString() 24 | labelRect = CGRect(x:0.0,y: 0.0,width: 200.0,height: 40.0) 25 | 26 | super.init(frame: frame) 27 | } 28 | 29 | required init(coder : NSCoder) { 30 | lineWidth = 0 31 | fillColor = UIColor.blackColor() 32 | labelColor = UIColor.blackColor() 33 | labelRect = CGRect(x:0.0,y: 0.0,width: 200.0,height: 40.0) 34 | 35 | super.init(coder:coder) 36 | } 37 | 38 | /* 39 | // Only override drawRect: if you perform custom drawing. 40 | // An empty implementation adversely affects performance during animation. 41 | */ 42 | override func drawRect(rect: CGRect) 43 | { 44 | var l:UILabel = UILabel() 45 | l.text = labelText 46 | l.frame = labelRect 47 | l.textColor = labelColor 48 | addSubview(l) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /CustomViewSwift/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.yume190.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /CustomViewSwift/LiveRenderKVC.swift: -------------------------------------------------------------------------------- 1 | // 2 | // LiveRenderKVC.swift 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2014/9/11. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | @IBDesignable 11 | class LiveRenderKVC: CustomViewTemplate { 12 | 13 | @IBOutlet var view: UIView! 14 | @IBOutlet weak var labelLeft: UILabel! 15 | @IBOutlet weak var labelRight: UILabel! 16 | 17 | 18 | override func setup() { 19 | super.setup() 20 | instantiateWithXib() 21 | self.addSubview(view) 22 | } 23 | 24 | override func className() -> String { 25 | return "LiveRenderKVC" 26 | } 27 | 28 | override func processViewSource() { 29 | labelLeft.text = viewSourceDictionary!["labelLeft"] as? String 30 | labelRight.text = viewSourceDictionary!["labelRight"] as? String 31 | } 32 | } -------------------------------------------------------------------------------- /CustomViewSwift/LiveRenderKVC.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /CustomViewSwift/ViewSource.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewSource.swift 3 | // apsmswift 4 | // 5 | // Created by APP559 on 2014/8/11. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | var ViewSourceInstance: ViewSource { 12 | get{ 13 | return ViewSource.sharedInstance 14 | } 15 | } 16 | 17 | class ViewSource: NSObject { 18 | 19 | class var sharedInstance: ViewSource { 20 | dispatch_once(&Inner.token) { 21 | Inner.instance = ViewSource() 22 | } 23 | return Inner.instance! 24 | } 25 | 26 | struct Inner { 27 | static var instance: ViewSource? 28 | static var token: dispatch_once_t = 0 29 | } 30 | 31 | func TestView1() -> NSDictionary{ 32 | return ["type":"YumeButton", 33 | "buttonTitle":"Push Me!!"] 34 | } 35 | 36 | func TestView2() -> NSDictionary{ 37 | return ["type":"YumeButton", 38 | "buttonTitle":"Push abc!!"] 39 | } 40 | 41 | func TestView3() -> NSDictionary{ 42 | return ["type":"YumeButton", 43 | "buttonTitle":"Push def!!"] 44 | } 45 | 46 | func SwiftKVC() -> NSDictionary{ 47 | return ["type":"LiveRenderKVC", 48 | "labelLeft":"lllll", 49 | "labelRight":"rr"] 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /CustomViewSwiftTests/CustomViewSwiftTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewSwiftTests.swift 3 | // CustomViewSwiftTests 4 | // 5 | // Created by Yume on 2014/6/3. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class CustomViewSwiftTests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | super.tearDown() 21 | } 22 | 23 | func testExample() { 24 | // This is an example of a functional test case. 25 | XCTAssert(true, "Pass") 26 | } 27 | 28 | func testPerformanceExample() { 29 | // This is an example of a performance test case. 30 | self.measureBlock() { 31 | // Put the code you want to measure the time of here. 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /CustomViewSwiftTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.yume190.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/project.xcworkspace/xcshareddata/CustomViewTest.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 1144986A-59CE-4705-A033-EEAD7DC7CA18 9 | IDESourceControlProjectName 10 | CustomViewTest 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 21FEF971-D14E-4B98-8AD4-3C2AB88509DF 14 | https://github.com/yume190/CustomView.git 15 | A6B33965A226072ACF430000273A167720004DF5 16 | https://github.com/yume190/CustomView.git 17 | 18 | IDESourceControlProjectPath 19 | CustomViewTest.xcodeproj 20 | IDESourceControlProjectRelativeInstallPathDictionary 21 | 22 | 21FEF971-D14E-4B98-8AD4-3C2AB88509DF 23 | ../..Test2 24 | A6B33965A226072ACF430000273A167720004DF5 25 | ../.. 26 | 27 | IDESourceControlProjectURL 28 | https://github.com/yume190/CustomView.git 29 | IDESourceControlProjectVersion 30 | 111 31 | IDESourceControlProjectWCCIdentifier 32 | A6B33965A226072ACF430000273A167720004DF5 33 | IDESourceControlProjectWCConfigurations 34 | 35 | 36 | IDESourceControlRepositoryExtensionIdentifierKey 37 | public.vcs.git 38 | IDESourceControlWCCIdentifierKey 39 | A6B33965A226072ACF430000273A167720004DF5 40 | IDESourceControlWCCName 41 | CustomView 42 | 43 | 44 | IDESourceControlRepositoryExtensionIdentifierKey 45 | public.vcs.git 46 | IDESourceControlWCCIdentifierKey 47 | 21FEF971-D14E-4B98-8AD4-3C2AB88509DF 48 | IDESourceControlWCCName 49 | CustomViewTest2 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/project.xcworkspace/xcuserdata/APP559.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yume190/CustomView/3847470236e8527bc29f66975cbda12f2ba4b8e8/CustomViewTest.xcodeproj/project.xcworkspace/xcuserdata/APP559.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/project.xcworkspace/xcuserdata/yume.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yume190/CustomView/3847470236e8527bc29f66975cbda12f2ba4b8e8/CustomViewTest.xcodeproj/project.xcworkspace/xcuserdata/yume.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/xcuserdata/APP559.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 24 | 36 | 37 | 38 | 40 | 52 | 53 | 54 | 56 | 66 | 67 | 68 | 70 | 82 | 83 | 84 | 86 | 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/xcuserdata/APP559.xcuserdatad/xcschemes/CustomViewObjc.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 52 | 53 | 54 | 55 | 61 | 62 | 64 | 65 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/xcuserdata/APP559.xcuserdatad/xcschemes/CustomViewSwift.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 52 | 53 | 54 | 55 | 61 | 62 | 64 | 65 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/xcuserdata/APP559.xcuserdatad/xcschemes/CustomViewTest.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 79 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/xcuserdata/APP559.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CustomViewObjc.xcscheme 8 | 9 | orderHint 10 | 1 11 | 12 | CustomViewSwift.xcscheme 13 | 14 | orderHint 15 | 2 16 | 17 | CustomViewTest.xcscheme 18 | 19 | orderHint 20 | 0 21 | 22 | 23 | SuppressBuildableAutocreation 24 | 25 | 4D8B2A8E1910E7AE0023EA7F 26 | 27 | primary 28 | 29 | 30 | 4D8B2AAF1910E7AE0023EA7F 31 | 32 | primary 33 | 34 | 35 | A87CF69B193DC5B4006BF9ED 36 | 37 | primary 38 | 39 | 40 | A87CF6A5193DC5B5006BF9ED 41 | 42 | primary 43 | 44 | 45 | A8D5CE6D193D9FF600D3A3E2 46 | 47 | primary 48 | 49 | 50 | A8D5CE77193D9FF600D3A3E2 51 | 52 | primary 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/xcuserdata/yume.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/xcuserdata/yume.xcuserdatad/xcschemes/CustomViewObjc.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 52 | 53 | 54 | 55 | 61 | 62 | 64 | 65 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/xcuserdata/yume.xcuserdatad/xcschemes/CustomViewSwift.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 52 | 53 | 54 | 55 | 61 | 62 | 64 | 65 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/xcuserdata/yume.xcuserdatad/xcschemes/CustomViewTest.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 57 | 63 | 64 | 65 | 66 | 67 | 73 | 74 | 75 | 76 | 85 | 87 | 93 | 94 | 95 | 96 | 97 | 98 | 104 | 106 | 112 | 113 | 114 | 115 | 117 | 118 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /CustomViewTest.xcodeproj/xcuserdata/yume.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CustomViewKit.xcscheme 8 | 9 | orderHint 10 | 3 11 | 12 | CustomViewObjc.xcscheme 13 | 14 | orderHint 15 | 1 16 | 17 | CustomViewSwift.xcscheme 18 | 19 | orderHint 20 | 2 21 | 22 | CustomViewTest.xcscheme 23 | 24 | orderHint 25 | 0 26 | 27 | 28 | SuppressBuildableAutocreation 29 | 30 | 4D8B2A8E1910E7AE0023EA7F 31 | 32 | primary 33 | 34 | 35 | 4D8B2AAF1910E7AE0023EA7F 36 | 37 | primary 38 | 39 | 40 | A84C31E11ABEE3E100AD8BF2 41 | 42 | primary 43 | 44 | 45 | A84C31EB1ABEE3E100AD8BF2 46 | 47 | primary 48 | 49 | 50 | A87CF69B193DC5B4006BF9ED 51 | 52 | primary 53 | 54 | 55 | A87CF6A5193DC5B5006BF9ED 56 | 57 | primary 58 | 59 | 60 | A8D5CE6D193D9FF600D3A3E2 61 | 62 | primary 63 | 64 | 65 | A8D5CE77193D9FF600D3A3E2 66 | 67 | primary 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /CustomViewTest/Custom.h: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewObjetiveC.h 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2014/6/3. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | IB_DESIGNABLE 11 | @interface Custom: UIView 12 | 13 | #ifdef IBInspectable 14 | @property (nonatomic) IBInspectable NSInteger lineWidth; 15 | @property (nonatomic) IBInspectable UIColor *fillColor; 16 | @property (nonatomic) IBInspectable NSString *labelText; 17 | @property (nonatomic) IBInspectable CGRect labelRect; 18 | #endif 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /CustomViewTest/Custom.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewObjetiveC.m 3 | // CustomViewTest 4 | // 5 | // Created by Yume on 2014/6/3. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import "Custom.h" 10 | 11 | @implementation Custom 12 | 13 | - (instancetype)initWithFrame:(CGRect)frame 14 | { 15 | self = [super initWithFrame:frame]; 16 | if (self) { 17 | // Initialization code 18 | } 19 | return self; 20 | } 21 | 22 | /* 23 | // Only override drawRect: if you perform custom drawing. 24 | // An empty implementation adversely affects performance during animation. 25 | */ 26 | - (void)drawRect:(CGRect)rect 27 | { 28 | UILabel *l =[[UILabel alloc] initWithFrame:_labelRect]; 29 | l.text = _labelText; 30 | // [self addSubview:l]; 31 | [l drawRect:rect]; 32 | 33 | // Drawing code 34 | CGContextRef context = UIGraphicsGetCurrentContext(); 35 | CGRect myFrame = self.bounds; 36 | 37 | // Set the line width to 10 and inset the rectangle by 38 | // 5 pixels on all sides to compensate for the wider line. 39 | // CGContextSetLineWidth(context, 10); 40 | CGContextSetLineWidth(context, _lineWidth); 41 | CGRectInset(myFrame, 5, 5); 42 | 43 | [_fillColor set]; 44 | UIRectFrame(myFrame); 45 | } 46 | 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /CustomViewTest/CustomViewTest-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | tw.com.align.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /CustomViewTest/CustomViewTest-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /CustomViewTest/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /CustomViewTest/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /CustomViewTest/MyPlayground.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CustomViewTest/MyPlayground.playground/section-1.swift: -------------------------------------------------------------------------------- 1 | // Playground - noun: a place where people can play 2 | 3 | import UIKit 4 | 5 | var str = "Hello, playground" 6 | 7 | var optionalString: String? = "Hello" 8 | optionalString == nil 9 | 10 | var optionalName: String? = nil//"John Appleseed" 11 | var greeting = "Hello!" 12 | if let name = optionalName { 13 | greeting = "Hello, \(name)" 14 | }else{ 15 | greeting = "Hello, \(optionalName)" 16 | } 17 | 18 | let vegetable = "red pepper" 19 | switch vegetable { 20 | case "celery": 21 | let vegetableComment = "Add some raisins and make ants on a log." 22 | case "cucumber", "watercress": 23 | let vegetableComment = "That would make a good tea sandwich." 24 | case let x where x.hasSuffix("pepper"): 25 | let vegetableComment = "Is it a spicy \(x)?" 26 | default: 27 | let vegetableComment = "Everything tastes good in soup." 28 | } 29 | 30 | let interestingNumbers = [ 31 | "Prime": [2, 3, 5, 7, 11, 13], 32 | "Fibonacci": [1, 1, 2, 3, 5, 8], 33 | "Square": [1, 4, 9, 16, 25], 34 | ] 35 | var largest = 0 36 | for (kind, numbers) in interestingNumbers { 37 | for number in numbers { 38 | if number > largest { 39 | largest = number 40 | } 41 | } 42 | } 43 | largest 44 | 45 | var n = 2 46 | while n < 100 { 47 | n = n * 2 48 | } 49 | n 50 | 51 | var m = 2 52 | do { 53 | m = m * 2 54 | } while m < 100 55 | m 56 | 57 | var firstForLoop = 0 58 | for i in 0..3 { 59 | firstForLoop += i 60 | } 61 | firstForLoop 62 | 63 | var secondForLoop = 0 64 | for var i = 0; i < 3; ++i { 65 | secondForLoop += 1 66 | } 67 | secondForLoop 68 | 69 | 70 | func getGasPrices(a:Int=1,b:Int=2,c:Int=3,numbers:Int...) -> (Int,Int,Int,Int) { 71 | var n:Int? = 0 72 | for nn in numbers{ 73 | n = n!+nn 74 | } 75 | return (a, b, c,n!) 76 | } 77 | getGasPrices() 78 | getGasPrices(10) 79 | getGasPrices(a: 10,b: 20) 80 | getGasPrices(c:30,b:20,a:10,1,2,3,4,5) 81 | 82 | 83 | func returnFifteen() -> Int { 84 | var y = 10 85 | func add() { 86 | y += 5 87 | } 88 | add() 89 | return y 90 | } 91 | returnFifteen() 92 | 93 | func makeIncrementer() -> (Int -> Int) { 94 | func addOne(number: Int) -> Int { 95 | return 1 + number 96 | } 97 | return addOne 98 | } 99 | var increment = makeIncrementer() 100 | increment(7) 101 | 102 | 103 | var numbers = [20, 19, 7, 12] 104 | 105 | numbers.map({ 106 | (number: Int) -> Int in 107 | let result = 3 * number 108 | return result 109 | }) 110 | 111 | numbers.map({ number in 3 * number }) 112 | numbers 113 | 114 | sort(numbers) { $0 > $1 } 115 | numbers 116 | 117 | class NamedShape { 118 | var numberOfSides: Int = 0 119 | var name: String 120 | 121 | init(name: String) { 122 | self.name = name 123 | } 124 | 125 | func simpleDescription() -> String { 126 | return "A shape with \(numberOfSides) sides." 127 | } 128 | } 129 | 130 | class EquilateralTriangle: NamedShape { 131 | var sideLength: Double = 0.0 132 | 133 | init(sideLength: Double, name: String) { 134 | self.sideLength = sideLength 135 | super.init(name: name) 136 | numberOfSides = 3 137 | } 138 | 139 | var perimeter: Double { 140 | get { 141 | return 3.0 * sideLength 142 | // return self.perimeter 143 | } 144 | set { 145 | sideLength = newValue / 0.5 146 | // self.perimeter = newValue / 0.5 147 | } 148 | } 149 | 150 | var perimeter2: Double { 151 | get { 152 | return 2.0 * sideLength 153 | } 154 | set (value){ 155 | sideLength = value / 1 156 | } 157 | } 158 | } 159 | 160 | var tt = EquilateralTriangle(sideLength: 1,name: "a") 161 | tt.perimeter = 10 162 | tt.perimeter 163 | 164 | tt.perimeter2 = 10 165 | tt.perimeter2 166 | 167 | class Square: NamedShape { 168 | var sideLength: Double 169 | 170 | init(sideLength: Double, name: String) { 171 | self.sideLength = sideLength 172 | super.init(name: name) 173 | numberOfSides = 4 174 | } 175 | 176 | func area() -> Double { 177 | return sideLength * sideLength 178 | } 179 | 180 | override func simpleDescription() -> String { 181 | return "A square with sides of length \(sideLength)." 182 | } 183 | } 184 | 185 | class TriangleAndSquare { 186 | var triangle: EquilateralTriangle { 187 | willSet { 188 | square.sideLength = newValue.sideLength 189 | } 190 | } 191 | 192 | var square: Square { 193 | willSet { 194 | triangle.sideLength = newValue.sideLength 195 | } 196 | } 197 | 198 | init(size: Double, name: String) { 199 | square = Square(sideLength: size, name: name) 200 | triangle = EquilateralTriangle(sideLength: size, name: name) 201 | } 202 | } 203 | var triangleAndSquare = TriangleAndSquare(size: 10, name: "another test shape") 204 | triangleAndSquare.square.sideLength 205 | triangleAndSquare.triangle.sideLength 206 | triangleAndSquare.square = Square(sideLength: 50, name: "larger square") 207 | triangleAndSquare.triangle.sideLength 208 | 209 | let optionalSquare: Square? = Square(sideLength: 2.5, name: "optional square") 210 | let sideLength = optionalSquare?.sideLength 211 | 212 | 213 | enum Rank: Int { 214 | case Ace = 1 215 | case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten 216 | case Jack, Queen, King 217 | func simpleDescription() -> String { 218 | switch self { 219 | case .Ace: 220 | return "ace" 221 | case .Jack: 222 | return "jack" 223 | case .Queen: 224 | return "queen" 225 | case .King: 226 | return "king" 227 | default: 228 | return String(self.toRaw()) 229 | } 230 | } 231 | } 232 | let ace = Rank.Ace 233 | ace.simpleDescription() 234 | //let aceRawValue = ace.toRaw() 235 | 236 | 237 | -------------------------------------------------------------------------------- /CustomViewTest/MyPlayground.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CustomViewTest/TemplateView1.h: -------------------------------------------------------------------------------- 1 | // 2 | // TemplateView2.h 3 | // test 4 | // 5 | // Created by ALIGN-APP on 2014/4/28. 6 | // Copyright (c) 2014年 ALIGN-APP. All rights reserved. 7 | // 8 | 9 | #import 10 | IB_DESIGNABLE 11 | @class TemplateView1; 12 | @protocol TemplateView1Delegate 13 | -(void)TemplateView:(TemplateView1*)templateView WithValueChange:(float)value; 14 | @end 15 | 16 | @interface TemplateView1 : UIView 17 | @property (strong, nonatomic) IBOutlet UILabel *labelTitle; 18 | @property (strong, nonatomic) IBOutlet UILabel *labelNumber; 19 | @property (strong, nonatomic) IBOutlet UIStepper *stepper; 20 | @property (strong, nonatomic) IBOutlet UISlider *slider; 21 | @property (strong, nonatomic) IBOutlet UILabel *labelMin; 22 | @property (strong, nonatomic) IBOutlet UILabel *labelDefault; 23 | @property (strong, nonatomic) IBOutlet UILabel *labelMax; 24 | @property (strong, nonatomic) IBOutlet UILabel *labelLeftTitle; 25 | @property (strong, nonatomic) IBOutlet UILabel *labelRightTitle; 26 | 27 | @property (nonatomic) IBInspectable NSInteger lineWidth; 28 | @property (nonatomic) IBInspectable UIColor *fillColor; 29 | 30 | @property (assign) NSString* vTitle; 31 | @property (assign) NSString* vLeftTitle; 32 | @property (assign) NSString* vRightTitle; 33 | @property (assign) NSNumber* vMin; 34 | @property (assign) NSNumber* vDefault; 35 | @property (assign) NSNumber* vMax; 36 | 37 | @property (nonatomic,strong) IBOutlet UIView * view; 38 | 39 | - (id)initWithCoder:(NSCoder *)aDecoder; 40 | -(void)resetViewValue; 41 | @property (weak) IBOutlet id delegate; 42 | 43 | - (id)initWithMin:(double)minValue WithMax:(double)maxValue WithDefault:(double)defaultValue; 44 | @end 45 | 46 | -------------------------------------------------------------------------------- /CustomViewTest/TemplateView1.m: -------------------------------------------------------------------------------- 1 | // 2 | // TemplateView2.m 3 | // test 4 | // 5 | // Created by ALIGN-APP on 2014/4/28. 6 | // Copyright (c) 2014年 ALIGN-APP. All rights reserved. 7 | // 8 | 9 | #import "TemplateView1.h" 10 | 11 | #define SLIDER_WAIT_INTERVAL 0.1 12 | 13 | @interface TemplateView1() 14 | { 15 | double viewDefaultValue; 16 | NSDate *beginTime; 17 | } 18 | 19 | @end 20 | 21 | @implementation TemplateView1 22 | @synthesize labelTitle; 23 | @synthesize labelLeftTitle; 24 | @synthesize labelRightTitle; 25 | @synthesize labelNumber; 26 | @synthesize stepper; 27 | @synthesize slider; 28 | @synthesize labelMin; 29 | @synthesize labelDefault; 30 | @synthesize labelMax; 31 | 32 | @synthesize vTitle; 33 | @synthesize vLeftTitle; 34 | @synthesize vRightTitle; 35 | @synthesize vMin; 36 | @synthesize vDefault; 37 | @synthesize vMax; 38 | 39 | - (void)awakeFromNib { 40 | labelTitle.text = vTitle; 41 | labelLeftTitle.text = vLeftTitle; 42 | labelRightTitle.text = vRightTitle; 43 | labelNumber.text = [NSString stringWithFormat:@" %0.f",[vDefault floatValue]]; 44 | 45 | [stepper setMinimumValue:[vMin floatValue]]; 46 | [stepper setMaximumValue:[vMax floatValue]]; 47 | [stepper setStepValue:1]; 48 | 49 | slider.minimumValue = [vMin floatValue]; 50 | slider.maximumValue = [vMax floatValue]; 51 | 52 | [self setViewValue:[vDefault floatValue]]; 53 | } 54 | 55 | - (void)setValue:(id)value forUndefinedKey:(NSString *)key { 56 | NSLog(@"HA! caught you trying to set undefined key %@ to %@",key,value); 57 | } 58 | 59 | - (void) setup{ 60 | NSString *nibName = NSStringFromClass([self class]); 61 | UINib *nib = [UINib nibWithNibName:nibName bundle:nil]; 62 | [nib instantiateWithOwner:self options:nil]; 63 | //Add the view loaded from the nib into self. 64 | [self addSubview:self.view]; 65 | } 66 | 67 | - (id)initWithCoder:(NSCoder *)aDecoder{ 68 | self = [super initWithCoder:aDecoder]; 69 | 70 | if (self) { 71 | [self setup]; 72 | 73 | self.layer.borderColor = [UIColor grayColor].CGColor ; 74 | self.layer.borderWidth = 3.0f; 75 | 76 | if( [self.layer respondsToSelector:@selector(setCornerRadius:)] ) 77 | [self.layer setCornerRadius:10]; 78 | 79 | [stepper addTarget:self action:@selector(stepperValueIschanged:) forControlEvents:UIControlEventValueChanged]; 80 | 81 | [slider addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged]; 82 | UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sliderTapped:)]; 83 | [slider addGestureRecognizer:tapGestureRecognizer]; 84 | 85 | viewDefaultValue = [vDefault floatValue]; 86 | 87 | beginTime = [NSDate date]; 88 | } 89 | return self; 90 | } 91 | 92 | - (id)initWithMin:(double)minValue WithMax:(double)maxValue WithDefault:(double)defaultValue 93 | { 94 | self = [super init]; 95 | if (self) { 96 | self.layer.borderColor = [UIColor grayColor].CGColor ; 97 | self.layer.borderWidth = 3.0f; 98 | 99 | if( [self.layer respondsToSelector:@selector(setCornerRadius:)] ) 100 | [self.layer setCornerRadius:10]; 101 | 102 | labelTitle=[[UILabel alloc] initWithFrame:CGRectMake(8, 5, 220, 26)]; 103 | [labelTitle setFont:[UIFont boldSystemFontOfSize:22]]; 104 | [self addSubview:labelTitle]; 105 | 106 | labelNumber=[[UILabel alloc] initWithFrame:CGRectMake(220, 0, 90, 56)]; 107 | labelNumber.text = [NSString stringWithFormat:@" %0.f",defaultValue]; 108 | labelNumber.textAlignment=YES; 109 | [labelNumber setFont:[UIFont systemFontOfSize:39]]; 110 | [self addSubview:labelNumber]; 111 | 112 | 113 | stepper=[[UIStepper alloc] initWithFrame:CGRectMake(220, 50, 94, 29)]; 114 | [stepper setMinimumValue:minValue]; 115 | [stepper setMaximumValue:maxValue]; 116 | [stepper setValue:defaultValue]; 117 | [stepper setStepValue:1]; 118 | [self addSubview:stepper]; 119 | 120 | slider=[[UISlider alloc] initWithFrame:CGRectMake(8, 30, 200, 37)]; 121 | slider.minimumValue = minValue; 122 | slider.maximumValue = maxValue; 123 | slider.value = defaultValue; 124 | UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sliderTapped:)]; 125 | [slider addGestureRecognizer:tapGestureRecognizer]; 126 | //为slider添加方法当slider的值改变时就会触发change方法 127 | slider.continuous = YES; 128 | [self addSubview:slider]; 129 | 130 | labelMin=[[UILabel alloc] initWithFrame:CGRectMake(8, 65, 50, 21)]; 131 | labelMin.text = [NSString stringWithFormat:@"%0.f",minValue]; 132 | [self addSubview:labelMin]; 133 | 134 | labelDefault=[[UILabel alloc] initWithFrame:CGRectMake(98, 65, 50, 21)]; 135 | labelDefault.text = [NSString stringWithFormat:@"%0.f",defaultValue]; 136 | [self addSubview:labelDefault]; 137 | 138 | labelMax=[[UILabel alloc] initWithFrame:CGRectMake(188, 65, 50, 21)]; 139 | labelMax.text = [NSString stringWithFormat:@"%0.f",maxValue]; 140 | [self addSubview:labelMax]; 141 | viewDefaultValue=defaultValue; 142 | } 143 | return self; 144 | } 145 | 146 | -(void)setViewValue:(float)value{ 147 | slider.value = value; 148 | stepper.value = value; 149 | labelNumber.text = [NSString stringWithFormat:@" %0.f",value]; 150 | [self.delegate TemplateView:self WithValueChange:value]; 151 | } 152 | 153 | - (IBAction)change:(UISlider *)sender{ 154 | NSDate *currentTime = [NSDate date]; 155 | NSTimeInterval interval = [currentTime timeIntervalSinceDate:beginTime]; 156 | if (interval > SLIDER_WAIT_INTERVAL) { 157 | NSLog(@"interval2 %f",interval); 158 | beginTime = currentTime; 159 | }else{ 160 | return; 161 | } 162 | 163 | int progresAsInt = (int)( slider.value +0.5f); 164 | [self setViewValue:progresAsInt]; 165 | } 166 | 167 | - (IBAction)sliderTouchEnd:(UISlider *)sender { 168 | NSLog(@"touch end"); 169 | 170 | int progresAsInt = (int)( slider.value +0.5f); 171 | [self setViewValue:progresAsInt]; 172 | } 173 | 174 | 175 | - (void)sliderTapped:(UIGestureRecognizer *)gestureRecognizer 176 | { 177 | UISlider* s = (UISlider*)gestureRecognizer.view; 178 | if (s.highlighted) 179 | return; 180 | CGPoint pt = [gestureRecognizer locationInView: s]; 181 | CGFloat percentage = pt.x / s.bounds.size.width; 182 | CGFloat delta = percentage * (s.maximumValue - s.minimumValue); 183 | CGFloat value = s.minimumValue + delta; 184 | [s setValue:value animated:YES]; 185 | int progresAsInt = (int)(slider.value +0.5f); 186 | [self setViewValue:progresAsInt]; 187 | } 188 | 189 | - (IBAction)stepperValueIschanged:(id)sender{ 190 | [self setViewValue:stepper.value]; 191 | } 192 | 193 | -(void)resetViewValue{ 194 | [self setViewValue:viewDefaultValue]; 195 | } 196 | 197 | @end 198 | 199 | -------------------------------------------------------------------------------- /CustomViewTest/TemplateView1.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 35 | 43 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 64 | 69 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /CustomViewTest/en.lproj/Gpro_icon(512x512).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yume190/CustomView/3847470236e8527bc29f66975cbda12f2ba4b8e8/CustomViewTest/en.lproj/Gpro_icon(512x512).png -------------------------------------------------------------------------------- /CustomViewTest/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CustomViewTest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CustomViewTest 4 | // 5 | // Created by APP559 on 2014/4/30. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "yumeAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([yumeAppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /CustomViewTest/yumeAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // yumeAppDelegate.h 3 | // CustomViewTest 4 | // 5 | // Created by APP559 on 2014/4/30. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface yumeAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /CustomViewTest/yumeAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // yumeAppDelegate.m 3 | // CustomViewTest 4 | // 5 | // Created by APP559 on 2014/4/30. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import "yumeAppDelegate.h" 10 | 11 | @implementation yumeAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 22 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /CustomViewTest/yumeViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // yumeViewController.h 3 | // CustomViewTest 4 | // 5 | // Created by APP559 on 2014/4/30. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface yumeViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /CustomViewTest/yumeViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // yumeViewController.m 3 | // CustomViewTest 4 | // 5 | // Created by APP559 on 2014/4/30. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import "yumeViewController.h" 10 | #import "TemplateView1.h" 11 | #import "CustomViewObjetiveC.h" 12 | 13 | @interface yumeViewController (){ 14 | CustomViewObjetiveC *v; 15 | } 16 | @end 17 | 18 | @implementation yumeViewController 19 | 20 | - (void)viewDidLoad 21 | { 22 | [super viewDidLoad]; 23 | // Do any additional setup after loading the view, typically from a nib. 24 | // v = [[CustomViewObjetiveC alloc]initWithFrame:CGRectMake(0, 0, 320, 160)]; 25 | // v.label.frame = CGRectMake(10, 10, 50, 50); 26 | // v.label.text = @"ttasdfttt"; 27 | // v.label.textColor = [UIColor purpleColor]; 28 | // [self.view addSubview:v]; 29 | } 30 | 31 | -(void)viewDidLayoutSubviews{ 32 | [super viewDidLayoutSubviews]; 33 | // v.layer.backgroundColor = [UIColor whiteColor].CGColor; 34 | v.backgroundColor = [UIColor orangeColor]; 35 | } 36 | 37 | - (void)didReceiveMemoryWarning 38 | { 39 | [super didReceiveMemoryWarning]; 40 | // Dispose of any resources that can be recreated. 41 | } 42 | 43 | -(void)TemplateView:(TemplateView1 *)templateView WithValueChange:(float)value{ 44 | NSLog(@"value : %0.f",value); 45 | } 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /CustomViewTest/zh-Hant.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CustomViewTest/zh-Hant.lproj/Main.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yume190/CustomView/3847470236e8527bc29f66975cbda12f2ba4b8e8/CustomViewTest/zh-Hant.lproj/Main.strings -------------------------------------------------------------------------------- /CustomViewTestTests/CustomViewTestTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | tw.com.align.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /CustomViewTestTests/CustomViewTestTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CustomViewTestTests.m 3 | // CustomViewTestTests 4 | // 5 | // Created by APP559 on 2014/4/30. 6 | // Copyright (c) 2014年 yume. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CustomViewTestTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation CustomViewTestTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /CustomViewTestTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CustomViewTestTests/zh-Hant.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /CustomView_LiveRender_KVC.md: -------------------------------------------------------------------------------- 1 | Combine custom view with xib, live render(IOS8) and KVC 2 | ====== 3 | 4 | ## custom view with xib + live render 5 | 6 | You must learn `custom view with xib` and `live render` first 7 | 8 | then, add some code in your CustomView.m 9 | 10 | we have some change at `setup` method 11 | 12 |
- (void) setup{
13 |     NSString *nibName = NSStringFromClass([self class]);
14 |     
15 |     //Bundle Identifier can be find at Target -> Your Framework -> Bundle Identifier
16 |     NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:@"com.yume190.CustomViewObjc"];
17 |     
18 |     UINib *nib = [UINib nibWithNibName:nibName bundle:frameworkBundle];
19 |     
20 |     [nib instantiateWithOwner:self options:nil];
21 |     //Add the view loaded from the nib into self.
22 |     [self addSubview:self.view];
23 | }
24 | 
25 | 26 | ## custom view + KVC 27 | 28 | Related Documents 29 | 30 | * [ViewSource.m](CustomViewObjc/ViewSource.m) 31 | * [CustomWithXibLiveRenderKVC.h](CustomViewObjc/CustomWithXibLiveRenderKVC.h) 32 | * [CustomWithXibLiveRenderKVC.m](CustomViewObjc/CustomWithXibLiveRenderKVC.m) 33 | * and storyboard 34 | 35 | -------------------------------------------------------------------------------- /KVC.md: -------------------------------------------------------------------------------- 1 | Key Value Coding 2 | ====== 3 | 4 | * My blog(Ver. Chinese) 5 | * [IOS KVC](http://yume190.github.io/categories/IOS/KVC/) 6 | 7 | * IOS Dev Lib 8 | 9 | * [Key-Value Coding Programming Guide](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/KeyValueCoding.html#//apple_ref/doc/uid/10000107-SW1) 10 | 11 | * Struct to NSValue 12 | 13 | * [How to wrap a Struct into NSObject](http://stackoverflow.com/questions/5691881/how-to-wrap-a-struct-into-nsobject) 14 | 15 | * [What's the best way to put a c-struct in an NSArray?](http://stackoverflow.com/questions/4516991/whats-the-best-way-to-put-a-c-struct-in-an-nsarray) 16 | 17 | * bou.io 18 | 19 | * A very nice KVC tutorial, and KVC Custom Collections Operators[Key-Value Coding: Custom Operators](http://bou.io/KVCCustomOperators.html#fn:3) 20 | * KVC Open Source using `x.kvc[]`[An alternative syntax for KVC](http://bou.io/KVCTrampoline.html) 21 | * [Several Approaches to Higher-Order Functions with Objective-C Collections](http://bou.io/HigherOrderFunctionsInObjectiveC.html) 22 | * [Filtering NSArray With Key-Value Coding](http://bou.io/FilteringNSArrayWithKeyValueCoding.html) 23 | 24 | * Implement KVC 25 | * [Let's Build Key-Value Coding](https://www.mikeash.com/pyblog/friday-qa-2013-02-08-lets-build-key-value-coding.html) 26 | 27 | * KVC tutorial 28 | * [Objective-C Lesson 13: Key-Value Coding](http://www.binpress.com/tutorial/objectivec-lesson-13-keyvalue-coding/79) 29 | * [Learn Objective-C: Advanced KVC](http://www.binpress.com/tutorial/learn-objectivec-advanced-kvc/80) 30 | 31 | * Nice PPT[Intro to Cocoa KVC/KVO and Bindings](http://www.slideshare.net/sergio.acosta/intro-to-cocoa-kvckvo-and-bindings-presentation) 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 CustomView (yume190@gmail.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /LiveRender.md: -------------------------------------------------------------------------------- 1 | Live Render(IOS Dev Library) 2 | ========== 3 | 4 | 中文版:[IOS Custom View Part 2](http://yume190.github.io/2014/09/26/IOS-Custom-View-Part-2/) 5 | 6 | * [Creating a Custom View that Renders in Interface Builder](https://developer.apple.com/library/prerelease/ios/recipes/xcode_help-IB_objects_media/CreatingaLiveViewofaCustomObject.html#//apple_ref/doc/uid/TP40014224-CH41-SW1) 7 | * By using the IBInspectable attribute to declare variables as inspectable properties, you allow Interface Builder to quickly rerender your custom view as you change the values of these properties in the Attributes inspector. You can attach the IBInspectable attribute to any property in a class declaration, class extension, or category for any type that’s supported by Interface Builder’s defined runtime attributes: __boolean, integer or floating point number, string, localized string, rectangle, point, size, color, range, and nil__. 8 | * If you need to create code for a custom view that runs only in Interface Builder, call that code from the method prepareForInterfaceBuilder. For example, while designing an app that uses the iPhone camera, you might want to draw an image that represents what the camera might capture. Although its compiled for runtime, code called from `prepareForInterfaceBuilder` never gets called except by Interface Builder at design time. 9 | * You can use the preprocessor macro `TARGET_INTERFACE_BUILDER` to specify code for inclusion with or exclusion from your custom view class. 10 | 11 | ### Quick Link 12 | 13 | * [Live Render Ver.Objetive-c (IOS 8)](#liveRenderObjc) 14 | * [Live Render Ver.Swift (IOS 8)](#liveRenderSwift) 15 | * Swift live render(use didset)[How to make awesome UI components in iOS 8 using Swift and XCode 6](http://www.weheartswift.com/make-awesome-ui-components-ios-8-using-swift-xcode-6/) 16 | 17 | -- 18 | 19 | # Live Render Ver.Objetive-c (IOS 8) 20 | 21 | Related Documents 22 | 23 | * [CustomView.h](CustomViewObjc/CustomViewObjetiveC.h) 24 | * [CustomView.m](CustomViewObjc/CustomViewObjetiveC.m) 25 | 26 | ### Step 1 __Very Important__ 27 | * Create a framework. 28 | * File -> New -> Target... 29 | * IOS -> Framework & Library -> Cocoa Touch Framework 30 | 31 | ### Step 2 32 | * Create a CustomView class inherit from UIView 33 | 34 | ### Step 3 35 | * Add `IB_DESIGNABLE` to your class 36 | 37 |
#import <UIKit/UIKit.h>
 38 | IB_DESIGNABLE
 39 | @interface YourCustomVIew : UIView
 40 | @end
 41 | 
42 | 43 | ### Step 4 44 | * Add some property with __`IBInspectable`__ 45 | 46 |
#import <UIKit/UIKit.h>
 47 | IB_DESIGNABLE
 48 | @interface YourCustomVIew : UIView
 49 | @property (nonatomic) IBInspectable NSInteger lineWidth;
 50 | @property (nonatomic) IBInspectable UIColor *fillColor;
 51 | @property (nonatomic) IBInspectable UIColor *labelColor;
 52 | @property (nonatomic) IBInspectable NSString *labelText;
 53 | @property (nonatomic) IBInspectable CGRect labelRect;
 54 | @end
 55 | 
56 | 57 | ### Step 5 (Branch 1) 58 | * Implement `drawRect` method 59 | 60 |
- (void)drawRect:(CGRect)rect
 61 | {
 62 |     UILabel *l =[[UILabel alloc] initWithFrame:_labelRect];
 63 |     l.text = _labelText;
 64 |     l.textColor = _labelColor;
 65 |     [self addSubview:l];
 66 | 
 67 |     // Drawing code
 68 |     CGContextRef context = UIGraphicsGetCurrentContext();
 69 |     CGRect    myFrame = self.bounds;
 70 | 
 71 |     // Set the line width to 10 and inset the rectangle by
 72 |     // 5 pixels on all sides to compensate for the wider line.
 73 |     CGContextSetLineWidth(context, _lineWidth);
 74 |     CGRectInset(myFrame, 5, 5);
 75 | 
 76 |     [_fillColor set];
 77 |     UIRectFrame(myFrame);
 78 | }
 79 | 
80 | 81 | ### Step 5 (Branch 2) 82 | 83 | * Implement `initWithCoder` method & `initWithFrame` method 84 | 85 |
@interface CustomViewObjetiveC(){
 86 |     dispatch_once_t onceTokenViewLiveRendering;
 87 | }
 88 | @property (nonatomic,strong) UILabel *label;
 89 | @end
 90 | 
 91 | @implementation CustomViewObjetiveC
 92 | 
 93 | - (instancetype)initWithCoder:(NSCoder *)aDecoder{
 94 |     self = [super initWithCoder:aDecoder];
 95 |     
 96 |     if (self) {
 97 |         [self setup];
 98 |     }
 99 |     return self;
100 | }
101 | 
102 | - (instancetype)initWithFrame:(CGRect)frame{
103 |     self = [super initWithFrame:frame];
104 |     
105 |     if (self) {
106 |         [self setup];
107 |     }
108 |     return self;
109 | }
110 | 
111 | -(void)setup{
112 |     _label = [UILabel new];
113 |     [self addSubview:_label];
114 |     self.backgroundColor = [UIColor whiteColor];
115 | }
116 | @end
117 | 
118 | 119 | ### Step 6 (Branch 2) 120 | 121 | * implement live render methods(`prepareForInterfaceBuilder` & `drawRect`) 122 | 123 | PS : some strange with live render methods.(I will explain at [Live Render Flow](#liveRenderFlow)) 124 | 125 |
-(void)prepareForInterfaceBuilder{
126 |     [self viewLiveRendering];
127 | }
128 | 
129 | - (void)drawRect:(CGRect)rect{ 
130 | #ifndef TARGET_INTERFACE_BUILDER
131 |     [self viewLiveRendering];
132 | #endif
133 | }
134 | 
135 | -(void)viewLiveRendering{
136 |     dispatch_once(&onceTokenViewLiveRendering, ^{
137 |         _label.frame = _labelRect;
138 |         _label.text = _labelText;
139 |         _label.textColor = _labelColor;
140 |     });
141 | }
142 | 
143 | 144 | -- 145 | 146 | # Live Render Ver.Swift (IOS 8) 147 | 148 | Related Documents 149 | 150 | * [CustomViewSwift.swift](CustomViewSwift/CustomViewWithSwift.swift) 151 | 152 | ### Step 1 __Very Important__ 153 | * Create a framework. 154 | * File -> New -> Target... 155 | * IOS -> Framework & Library -> Cocoa Touch Framework 156 | 157 | ### Step 2 158 | * Create a CustomView class inherit from UIView 159 | 160 | ### Step 3 161 | * Add `@IBDesignable` to your class 162 | 163 |
import UIKit
164 | @IBDesignable
165 | class CustomViewWithSwift: UIView {
166 | }
167 | 
168 | 169 | ### Step 4 170 | * Add instance variable and implement constructor. `init(coder : NSCoder)` 171 | 172 |
import UIKit
173 | @IBDesignable
174 | class CustomViewWithSwift: UIView {
175 | 
176 |     @IBInspectable var labelColor: UIColor
177 |     @IBInspectable var labelText: NSString = ""
178 |     @IBInspectable var labelRect: CGRect
179 | 
180 |     init(coder : NSCoder) {
181 |         labelColor = UIColor.blackColor()
182 |         //labelText = NSString()
183 |         labelRect = CGRect(x:0.0,y: 0.0,width: 200.0,height: 40.0)
184 | 
185 |         super.init(coder:coder)
186 |     }
187 | }
188 | 
189 | 190 | ### Step 5 191 | * Override `drawRect` method 192 | 193 |
override func drawRect(rect: CGRect)
194 | {
195 |     var l:UILabel = UILabel()
196 |     l.text = labelText
197 |     l.frame = labelRect
198 |     l.textColor = labelColor
199 |     addSubview(l)
200 | }
201 | 
202 | 203 | # Live Render Flow 204 | 205 | | | APP running | `Debug Selected Views`
(`Live Rendering`) |Function| 206 | | :------------ |:--------------------:|:-----------------------------------------------:|:------:| 207 | |path |`initWithCoder:`




⬇︎
`drawRect:`|`initWithFrame:`

⬇︎
`prepareForInterfaceBuilder`

⬇︎
`drawRect:`|init method


Live Render 1


Draw| 208 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | CustomView 2 | ========== 3 | 4 | IOS Custom View with xib(IOS 7 & 8) and Live Render (IOS 8) 5 | 6 | * [Custom View With xib (IOS 7 & 8)](CustomView.md) 7 | * [Live Render (IOS 8)](LiveRender.md) 8 | * [Key Value Coding](KVC.md) 9 | * [Custom View with Xib + Live Render + KVC](CustomView_LiveRender_KVC.md) 10 | * WWDC 2014 Session 401 11 | * [Debug Selected Views](WWDC_2014_Session_401.md/#debugSelectedViews) 12 | * [Debug View Hierarchy](WWDC_2014_Session_401.md/#debugViewHierarchy) 13 | 14 | --- 15 | 16 | # CustomViewKit 17 | 18 | ### Manual Install 19 | 20 | You can download this repo and drag `CustomViewKit` to your project. 21 | 22 | then find the swift file `CustomViewLight.swift`, and replace `bundleIdentifier return value` to your bundleIdentifier 23 | 24 | ### Install with cocoapod 25 | 26 | Add a Podfile at your project 27 | 28 | touch Podfile 29 | 30 | Add CustomViewKit pod 31 | 32 | ``` 33 | platform :ios, '8.0' 34 | use_frameworks! 35 | pod 'CustomView', '~> 1.4' 36 | ``` 37 | 38 | ~~then create a swift file `CustomViewKitExtension.swift`, and override `bundleIdentifier` method~~ 39 | 40 | ### Usage 41 | 42 | ##### Only code 43 | 44 | Override `setup` method and add your custom code 45 | 46 | ``` 47 | import UIKit 48 | import CustomView 49 | 50 | class CV1: CustomViewLight { 51 | 52 | override func setup() { 53 | super.setup() 54 | // custom code 55 | var c = UILabel(frame: CGRectMake(0, 0, 100, 100)) 56 | c.text="1000" 57 | self.view?.addSubview(c) 58 | } 59 | 60 | } 61 | ``` 62 | 63 | ##### With xib 64 | 65 | Create swift file and xib file with same name 66 | 67 | * CV2.swift 68 | * CV2.xib 69 | 70 | ``` 71 | import UIKit 72 | import CustomView 73 | 74 | class CV2: CustomViewLayerStyle { 75 | @IBOutlet weak var label1: UILabel! 76 | @IBOutlet weak var label2: UILabel! 77 | @IBOutlet weak var label3: UILabel! 78 | } 79 | ``` 80 | 81 | Set `File's Owner` for your xib 82 | 83 | ![File's Owner](/images/i5.png) 84 | 85 | ### Custom Style 86 | 87 | ##### Add your custom style 88 | 89 | ``` 90 | extension ViewStyles { 91 | 92 | public func customStyle1() -> ViewStyle{ 93 | return ViewStyle().set(borderWidth:20).set(borderColor:UIColor.darkGrayColor()).set(cornorRadius:20) 94 | } 95 | 96 | public func customStyle2() -> ViewStyle{ 97 | return ViewStyle().set(borderWidth:30).set(borderColor:UIColor.greenColor()).set(cornorRadius:30) 98 | } 99 | } 100 | ``` 101 | 102 | ##### Use your custom style 103 | 104 | Set style by string`(method name)`, and `CustomViewLayerStyle` will find the method with KVC(Key Value Coding). 105 | 106 | ``` 107 | var cv2 = CV2(frame:CGRectMake(0, 100, 150, 150)) 108 | cv2.style = "customStyle1" 109 | ``` 110 | 111 | ### Custom View Source 112 | 113 | ##### Add your custom view source 114 | 115 | > NOTE : return type must be `ViewSource` 116 | 117 | ``` 118 | extension ViewSources { 119 | 120 | public var cv2Source1:ViewSource 121 | { 122 | get { 123 | return YumeViewSource(){ 124 | (CV2) -> () in 125 | CV2.label1.text = "11111" 126 | CV2.label2.text = "22222" 127 | CV2.label3.text = "33333" 128 | } 129 | } 130 | } 131 | 132 | public func cv2Source2() -> ViewSource{ 133 | return YumeViewSource(){ 134 | (CV2) -> () in 135 | CV2.label1.text = "abc" 136 | CV2.label2.text = "123" 137 | CV2.label3.text = "xyz" 138 | } 139 | } 140 | } 141 | ``` 142 | 143 | ##### Use your custom view source 144 | 145 | ``` 146 | var cv2 = CV2(frame:CGRectMake(0, 100, 150, 150)) 147 | cv2.viewSource = "cv2Source1" 148 | ``` -------------------------------------------------------------------------------- /WWDC_2014_Session_401.md: -------------------------------------------------------------------------------- 1 | WWDC 2014 Session 401 2 | ======== 3 | 4 | * [Debug Selected Views](#debugSelectedViews) 5 | * [Debug View Hierarchy](#debugViewHierarchy) 6 | 7 | # Debug Selected Views 8 | 9 | * You must click target view and you can find this future below 10 | 11 | ![Imgae 1](images/i1.png) 12 | 13 | # Debug View Hierarchy 14 | 15 | * This future must running your APP, and you can find it at below. 16 | 17 | ![Imgae 2](images/i2.png) 18 | 19 | or 20 | 21 | ![Imgae 3](images/i3.png) 22 | -------------------------------------------------------------------------------- /images/i1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yume190/CustomView/3847470236e8527bc29f66975cbda12f2ba4b8e8/images/i1.png -------------------------------------------------------------------------------- /images/i2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yume190/CustomView/3847470236e8527bc29f66975cbda12f2ba4b8e8/images/i2.png -------------------------------------------------------------------------------- /images/i3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yume190/CustomView/3847470236e8527bc29f66975cbda12f2ba4b8e8/images/i3.png -------------------------------------------------------------------------------- /images/i5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yume190/CustomView/3847470236e8527bc29f66975cbda12f2ba4b8e8/images/i5.png --------------------------------------------------------------------------------