Skip to content

Commit

Permalink
Add SwiftXibView.
Browse files Browse the repository at this point in the history
- Easy class  to use xib.
  • Loading branch information
kuyu12 committed Dec 1, 2018
1 parent e7b6000 commit d2e1e58
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
10 changes: 10 additions & 0 deletions SwiftXib/SwiftXib.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
0320F71821B30E19003BF605 /* SwiftXib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0320F70E21B30E19003BF605 /* SwiftXib.framework */; };
0320F71D21B30E19003BF605 /* SwiftXibTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0320F71C21B30E19003BF605 /* SwiftXibTests.swift */; };
0320F71F21B30E19003BF605 /* SwiftXib.h in Headers */ = {isa = PBXBuildFile; fileRef = 0320F71121B30E19003BF605 /* SwiftXib.h */; settings = {ATTRIBUTES = (Public, ); }; };
0320F72921B30E6C003BF605 /* SwiftXibView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0320F72821B30E6C003BF605 /* SwiftXibView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -29,6 +30,7 @@
0320F71721B30E19003BF605 /* SwiftXibTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftXibTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
0320F71C21B30E19003BF605 /* SwiftXibTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftXibTests.swift; sourceTree = "<group>"; };
0320F71E21B30E19003BF605 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0320F72821B30E6C003BF605 /* SwiftXibView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftXibView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -73,6 +75,7 @@
children = (
0320F71121B30E19003BF605 /* SwiftXib.h */,
0320F71221B30E19003BF605 /* Info.plist */,
0320F72821B30E6C003BF605 /* SwiftXibView.swift */,
);
path = SwiftXib;
sourceTree = "<group>";
Expand Down Expand Up @@ -148,6 +151,7 @@
TargetAttributes = {
0320F70D21B30E19003BF605 = {
CreatedOnToolsVersion = 10.1;
LastSwiftMigration = 1010;
};
0320F71621B30E19003BF605 = {
CreatedOnToolsVersion = 10.1;
Expand Down Expand Up @@ -194,6 +198,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0320F72921B30E6C003BF605 /* SwiftXibView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -341,6 +346,7 @@
0320F72321B30E19003BF605 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
Expand All @@ -358,6 +364,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.yairHadad.SwiftXib;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -366,6 +373,7 @@
0320F72421B30E19003BF605 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
Expand All @@ -391,6 +399,7 @@
0320F72621B30E19003BF605 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = E82HAQFSWT;
INFOPLIST_FILE = SwiftXibTests/Info.plist;
Expand All @@ -409,6 +418,7 @@
0320F72721B30E19003BF605 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = E82HAQFSWT;
INFOPLIST_FILE = SwiftXibTests/Info.plist;
Expand Down
4 changes: 0 additions & 4 deletions SwiftXib/SwiftXib/SwiftXib.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@ FOUNDATION_EXPORT double SwiftXibVersionNumber;

//! Project version string for SwiftXib.
FOUNDATION_EXPORT const unsigned char SwiftXibVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <SwiftXib/PublicHeader.h>


69 changes: 69 additions & 0 deletions SwiftXib/SwiftXib/SwiftXibView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// SwiftXibView.swift
// SwiftXib
//
// Created by yair hadad on 01/12/2018.
// Copyright © 2018 yair hadad. All rights reserved.
//

import Foundation

/**
Base view for xib View
- Guidelines:
- **override nibName property.**
- use setUI metode for initializ views.
*/
open class SwiftXibView : UIView {
open var nibName : String { get {return ""} }

/**
- parameters:
- frame: frame of view
*/
override init(frame: CGRect) {
// 2. call super.init(frame:)
super.init(frame: frame)
// 3. Setup view from .xib file
self.xibSetup()
self.setUI()
}

/**
- parameters:
- aDecoder: coder of view
*/
required public init?(coder aDecoder: NSCoder) {
// 2. call super.init(coder:)
super.init(coder: aDecoder)
// 3. Setup view from .xib file
xibSetup()
self.setUI()
}

var view: UIView!

fileprivate func xibSetup() {
view = loadViewFromNib()
// use bounds not frame or it'll be offset
view.frame = bounds
// Make the view stretch with containing view
view.autoresizingMask = [UIView.AutoresizingMask.flexibleWidth, UIView.AutoresizingMask.flexibleHeight]
// Adding custom subview on top of our view (over any custom drawing > see note below)
addSubview(view)
}

fileprivate func loadViewFromNib() -> UIView {
let bundle = Bundle(for: type(of: self))
let nib:UINib = UINib(nibName: self.nibName, bundle: bundle)
// Assumes UIView is top level and only object in CustomView.xib file
let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
return view
}

/**
setUI is call Immediately after the class is initialized
*/
open func setUI(){}

}

0 comments on commit d2e1e58

Please sign in to comment.