IOS Custom View with xib(IOS 7 & 8) and Live Render (IOS 8)
- Custom View With xib (IOS 7 & 8)
- Live Render (IOS 8)
- Key Value Coding
- Custom View with Xib + Live Render + KVC
- WWDC 2014 Session 401
You can download this repo and drag CustomViewKit
to your project.
then find the swift file CustomViewLight.swift
, and replace bundleIdentifier return value
to your bundleIdentifier
Add a Podfile at your project
touch Podfile
Add CustomViewKit pod
platform :ios, '8.0'
use_frameworks!
pod 'CustomView', '~> 1.4'
then create a swift file CustomViewKitExtension.swift
, and override bundleIdentifier
method
Override setup
method and add your custom code
import UIKit
import CustomView
class CV1: CustomViewLight {
override func setup() {
super.setup()
// custom code
var c = UILabel(frame: CGRectMake(0, 0, 100, 100))
c.text="1000"
self.view?.addSubview(c)
}
}
Create swift file and xib file with same name
- CV2.swift
- CV2.xib
import UIKit
import CustomView
class CV2: CustomViewLayerStyle {
@IBOutlet weak var label1: UILabel!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var label3: UILabel!
}
Set File's Owner
for your xib
extension ViewStyles {
public func customStyle1() -> ViewStyle{
return ViewStyle().set(borderWidth:20).set(borderColor:UIColor.darkGrayColor()).set(cornorRadius:20)
}
public func customStyle2() -> ViewStyle{
return ViewStyle().set(borderWidth:30).set(borderColor:UIColor.greenColor()).set(cornorRadius:30)
}
}
Set style by string(method name)
, and CustomViewLayerStyle
will find the method with KVC(Key Value Coding).
var cv2 = CV2(frame:CGRectMake(0, 100, 150, 150))
cv2.style = "customStyle1"
NOTE : return type must be
ViewSource
extension ViewSources {
public var cv2Source1:ViewSource
{
get {
return YumeViewSource<CV2>(){
(CV2) -> () in
CV2.label1.text = "11111"
CV2.label2.text = "22222"
CV2.label3.text = "33333"
}
}
}
public func cv2Source2() -> ViewSource{
return YumeViewSource<CV2>(){
(CV2) -> () in
CV2.label1.text = "abc"
CV2.label2.text = "123"
CV2.label3.text = "xyz"
}
}
}
var cv2 = CV2(frame:CGRectMake(0, 100, 150, 150))
cv2.viewSource = "cv2Source1"