Skip to content

Commit

Permalink
Now the library permit to load the PMAlertController bundle when used…
Browse files Browse the repository at this point in the history
… via Cocoapods
  • Loading branch information
pmusolino committed May 10, 2016
1 parent 3bca27e commit fbb4cfc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions Library/PMAlertController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public class PMAlertController: UIViewController {
public convenience init(title: String, description: String, image: UIImage?, style: PMAlertControllerStyle) {
self.init()

let nib = NSBundle.mainBundle().loadNibNamed("PMAlertController", owner: self, options: nil)
self.view = nib[0] as! UIView
let nib = loadNibAlertController()
if nib != nil{
self.view = nib![0] as! UIView
}

self.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
self.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
Expand All @@ -46,7 +48,7 @@ public class PMAlertController: UIViewController {

//if alert width = 270, else width = screen width - 36
style == .Alert ? (alertViewWidthConstraint.constant = 270) : (alertViewWidthConstraint.constant = UIScreen.mainScreen().bounds.width - 36)


setShadowAlertView()
}
Expand Down Expand Up @@ -77,4 +79,26 @@ public class PMAlertController: UIViewController {
alertView.layer.shadowRadius = 8
alertView.layer.shadowOpacity = 0.3
}

private func loadNibAlertController() -> [AnyObject]?{
let podBundle = NSBundle(forClass: self.classForCoder)

if let bundleURL = podBundle.URLForResource("PMAlertController", withExtension: "bundle") {

if let bundle = NSBundle(URL: bundleURL) {
return bundle.loadNibNamed("PMAlertController", owner: self, options: nil)
}
else {
assertionFailure("Could not load the bundle")
}

}
else if let nib = NSBundle.mainBundle().loadNibNamed("PMAlertController", owner: self, options: nil) {
return nib
}
else{
assertionFailure("Could not create a path to the bundle")
}
return nil
}
}
2 changes: 1 addition & 1 deletion PMAlertController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/Codeido/PMAlertController.git", :tag => "1.0.0" }
s.source_files = "Library/**/*"
s.resource_bundles = {
'PMAlertController' => ['Library/Resources/*.png']
'PMAlertController' => ['Library/Resources/*.png', 'Library/**/*.xib']
}
s.framework = "UIKit"
s.requires_arc = true
Expand Down

0 comments on commit fbb4cfc

Please sign in to comment.