This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var firstScheme:String? { | |
get { | |
if let schemes: AnyObject? = NSBundle.mainBundle().infoDictionary?["CFBundleURLTypes"]?[0]["CFBundleURLSchemes"] { | |
if let scheme = schemes?[0] as? String { | |
return scheme | |
} | |
} | |
return nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UILabel { | |
func setStrikethrough(text:String, color:UIColor = UIColor.blackColor()) { | |
let attributedText = NSAttributedString(string: text , attributes: [NSStrikethroughStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue, NSStrikethroughColorAttributeName: color]) | |
self.attributedText = attributedText | |
} | |
func setLineHeight(lineHeight: CGFloat) { | |
let text = self.text | |
if let text = text { | |
let attributeString = NSMutableAttributedString(string: text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var randomString: String { | |
get { | |
let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | |
let len = 20 // length | |
let randomString : NSMutableString = NSMutableString(capacity: len) | |
for (var i=0; i < len; i++){ | |
let length = UInt32 (letters.length) | |
let rand = arc4random_uniform(length) | |
randomString.appendFormat("%C", letters.characterAtIndex(Int(rand))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Int { | |
var yyyyMMddHHmm: String { | |
get { | |
let date = NSDate(timeIntervalSince1970: NSTimeInterval(self)/1000) | |
let dateFormatter = NSDateFormatter() | |
dateFormatter.locale = NSLocale(localeIdentifier: "en_US") | |
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Int { | |
var trimZero: String { | |
get { | |
return String(format: "%g", Double(self)) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIWindow { | |
func switchToController(_ controller: UIViewController) { | |
if rootViewController != nil { | |
setNewRootViewController(controller) | |
} else { | |
rootViewController = controller | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIApplication { | |
class func topViewController(_ base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? { | |
if let navigationController = base as? UINavigationController, navigationController.viewControllers.count > 0 { | |
return topViewController(navigationController.visibleViewController) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIView { | |
func searchVisualEffectsSubview() -> UIVisualEffectView? { | |
if let visualEffectView = self as? UIVisualEffectView { | |
return visualEffectView | |
} else { | |
for subview in subviews { | |
if let found = subview.searchVisualEffectsSubview() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import CoreGraphics | |
extension UIView { | |
func insetsInContentView(_ contentView: UIView) -> UIEdgeInsets { | |
return UIEdgeInsets( | |
top: frame.minY, | |
left: frame.minX, | |
bottom: contentView.frame.height - frame.minY - frame.height, |
NewerOlder