Commit 4ebb7ac7 by Daniel Dahan

updated to Xcode beta 4

parent d52f210d
...@@ -63,7 +63,7 @@ public struct Animation { ...@@ -63,7 +63,7 @@ public struct Animation {
public static func delay(time: TimeInterval, completion: ()-> Void) -> AnimationDelayCancelBlock? { public static func delay(time: TimeInterval, completion: ()-> Void) -> AnimationDelayCancelBlock? {
func dispatch_later(completion: ()-> Void) { func dispatch_later(completion: ()-> Void) {
DispatchQueue.main.after(when: DispatchTime.now() + time, execute: completion) DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + time, execute: completion)
} }
var cancelable: AnimationDelayCancelBlock? var cancelable: AnimationDelayCancelBlock?
......
...@@ -36,8 +36,8 @@ public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControl ...@@ -36,8 +36,8 @@ public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControl
let toView : UIView = transitionContext.view(forKey: UITransitionContextToViewKey)! let toView : UIView = transitionContext.view(forKey: UITransitionContextToViewKey)!
toView.alpha = 0 toView.alpha = 0
transitionContext.containerView().addSubview(fromView) transitionContext.containerView.addSubview(fromView)
transitionContext.containerView().addSubview(toView) transitionContext.containerView.addSubview(toView)
UIView.animate(withDuration: transitionDuration(using: transitionContext), UIView.animate(withDuration: transitionDuration(using: transitionContext),
animations: { _ in animations: { _ in
......
...@@ -119,10 +119,6 @@ public class Button: UIButton { ...@@ -119,10 +119,6 @@ public class Button: UIButton {
layoutShadowPath() layoutShadowPath()
} }
public override func alignmentRectInsets() -> UIEdgeInsets {
return UIEdgeInsets.zero
}
/** /**
Triggers the pulse animation. Triggers the pulse animation.
- Parameter point: A Optional point to pulse from, otherwise pulses - Parameter point: A Optional point to pulse from, otherwise pulses
......
...@@ -32,7 +32,7 @@ import UIKit ...@@ -32,7 +32,7 @@ import UIKit
import AVFoundation import AVFoundation
public class CapturePreview: View { public class CapturePreview: View {
public override class func layerClass() -> AnyClass { public override class var layerClass: AnyClass {
return AVCaptureVideoPreviewLayer.self return AVCaptureVideoPreviewLayer.self
} }
......
...@@ -69,6 +69,10 @@ public class CollectionViewLayout: UICollectionViewLayout { ...@@ -69,6 +69,10 @@ public class CollectionViewLayout: UICollectionViewLayout {
/// Spacing between items. /// Spacing between items.
public var interimSpace: InterimSpace = 0 public var interimSpace: InterimSpace = 0
public override var collectionViewContentSize: CGSize {
return contentSize
}
/** /**
Retrieves the index paths for the items within the passed in CGRect. Retrieves the index paths for the items within the passed in CGRect.
- Parameter rect: A CGRect that acts as the bounds to find the items within. - Parameter rect: A CGRect that acts as the bounds to find the items within.
...@@ -113,10 +117,6 @@ public class CollectionViewLayout: UICollectionViewLayout { ...@@ -113,10 +117,6 @@ public class CollectionViewLayout: UICollectionViewLayout {
return .vertical == scrollDirection ? newBounds.width != collectionView!.bounds.width : newBounds.height != collectionView!.bounds.height return .vertical == scrollDirection ? newBounds.width != collectionView!.bounds.width : newBounds.height != collectionView!.bounds.height
} }
public override func collectionViewContentSize() -> CGSize {
return contentSize
}
public override func prepare() { public override func prepare() {
if let dataSource: CollectionViewDataSource = collectionView?.dataSource as? CollectionViewDataSource { if let dataSource: CollectionViewDataSource = collectionView?.dataSource as? CollectionViewDataSource {
prepareLayoutForItems(dataSourceItems: dataSource.items()) prepareLayoutForItems(dataSourceItems: dataSource.items())
......
...@@ -32,13 +32,13 @@ import UIKit ...@@ -32,13 +32,13 @@ import UIKit
public struct Color { public struct Color {
// clear // clear
public static let clear: UIColor = UIColor.clear() public static let clear: UIColor = UIColor.clear
// white // white
public static let white: UIColor = UIColor.white() public static let white: UIColor = UIColor.white
// black // black
public static let black: UIColor = UIColor.black() public static let black: UIColor = UIColor.black
// dark text // dark text
public struct darkText { public struct darkText {
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
import UIKit import UIKit
public class ControlView : View { public class ControlView: View {
/// Will render the view. /// Will render the view.
public var willRenderView: Bool { public var willRenderView: Bool {
return 0 < width && 0 < height return 0 < width && 0 < height
...@@ -73,6 +73,10 @@ public class ControlView : View { ...@@ -73,6 +73,10 @@ public class ControlView : View {
} }
} }
public override var intrinsicContentSize: CGSize {
return CGSize(width: width, height: 44)
}
/// Grid cell factor. /// Grid cell factor.
@IBInspectable public var gridFactor: CGFloat = 24 { @IBInspectable public var gridFactor: CGFloat = 24 {
didSet { didSet {
...@@ -141,7 +145,7 @@ public class ControlView : View { ...@@ -141,7 +145,7 @@ public class ControlView : View {
/// Basic initializer. /// Basic initializer.
public init() { public init() {
super.init(frame: CGRect.zero) super.init(frame: CGRect.zero)
frame.size = intrinsicContentSize() frame.size = intrinsicContentSize
} }
/** /**
...@@ -151,7 +155,7 @@ public class ControlView : View { ...@@ -151,7 +155,7 @@ public class ControlView : View {
*/ */
public init(leftControls: [UIView]? = nil, rightControls: [UIView]? = nil) { public init(leftControls: [UIView]? = nil, rightControls: [UIView]? = nil) {
super.init(frame: CGRect.zero) super.init(frame: CGRect.zero)
frame.size = intrinsicContentSize() frame.size = intrinsicContentSize
prepareProperties(leftControls: leftControls, rightControls: rightControls) prepareProperties(leftControls: leftControls, rightControls: rightControls)
} }
...@@ -171,7 +175,7 @@ public class ControlView : View { ...@@ -171,7 +175,7 @@ public class ControlView : View {
// leftControls // leftControls
if let v = leftControls { if let v = leftControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize().width let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
...@@ -191,7 +195,7 @@ public class ControlView : View { ...@@ -191,7 +195,7 @@ public class ControlView : View {
// rightControls // rightControls
if let v = rightControls { if let v = rightControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize().width let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
...@@ -212,11 +216,7 @@ public class ControlView : View { ...@@ -212,11 +216,7 @@ public class ControlView : View {
} }
} }
} }
public override func intrinsicContentSize() -> CGSize {
return CGSize(width: width, height: 44)
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method it is recommended to override the prepareView method
......
...@@ -76,12 +76,12 @@ public struct Device { ...@@ -76,12 +76,12 @@ public struct Device {
/// Retrieves the current device type. /// Retrieves the current device type.
public static var userInterfaceIdiom: UIUserInterfaceIdiom { public static var userInterfaceIdiom: UIUserInterfaceIdiom {
return UIDevice.current().userInterfaceIdiom return UIDevice.current.userInterfaceIdiom
} }
/// A Boolean indicating if the device is in Landscape mode. /// A Boolean indicating if the device is in Landscape mode.
public static var isLandscape: Bool { public static var isLandscape: Bool {
return UIApplication.shared().statusBarOrientation.isLandscape return UIApplication.shared.statusBarOrientation.isLandscape
} }
/// A Boolean indicating if the device is in Portrait mode. /// A Boolean indicating if the device is in Portrait mode.
...@@ -91,32 +91,32 @@ public struct Device { ...@@ -91,32 +91,32 @@ public struct Device {
/// The current UIInterfaceOrientation value. /// The current UIInterfaceOrientation value.
public static var orientation: UIInterfaceOrientation { public static var orientation: UIInterfaceOrientation {
return UIApplication.shared().statusBarOrientation return UIApplication.shared.statusBarOrientation
} }
/// Retrieves the device status bar style. /// Retrieves the device status bar style.
public static var statusBarStyle: UIStatusBarStyle { public static var statusBarStyle: UIStatusBarStyle {
get { get {
return UIApplication.shared().statusBarStyle return UIApplication.shared.statusBarStyle
} }
set(value) { set(value) {
UIApplication.shared().statusBarStyle = value UIApplication.shared.statusBarStyle = value
} }
} }
/// Retrieves the device status bar hidden state. /// Retrieves the device status bar hidden state.
public static var isStatusBarHidden: Bool { public static var isStatusBarHidden: Bool {
get { get {
return UIApplication.shared().isStatusBarHidden return UIApplication.shared.isStatusBarHidden
} }
set(value) { set(value) {
UIApplication.shared().isStatusBarHidden = value UIApplication.shared.isStatusBarHidden = value
} }
} }
/// Retrieves the device bounds. /// Retrieves the device bounds.
public static var bounds: CGRect { public static var bounds: CGRect {
return UIScreen.main().bounds return UIScreen.main.bounds
} }
/// Retrieves the device width. /// Retrieves the device width.
...@@ -131,6 +131,6 @@ public struct Device { ...@@ -131,6 +131,6 @@ public struct Device {
/// Retrieves the device scale. /// Retrieves the device scale.
public static var scale: CGFloat { public static var scale: CGFloat {
return UIScreen.main().scale return UIScreen.main.scale
} }
} }
...@@ -86,7 +86,7 @@ private class FontLoader { ...@@ -86,7 +86,7 @@ private class FontLoader {
let bundle = Bundle(for: FontLoader.self) let bundle = Bundle(for: FontLoader.self)
let identifier = bundle.bundleIdentifier let identifier = bundle.bundleIdentifier
let fontURL = true == identifier?.hasPrefix("org.cocoapods") ? bundle.urlForResource(name, withExtension: "ttf", subdirectory: "io.cosmicmind.material.fonts.bundle") : bundle.urlForResource(name, withExtension: "ttf") let fontURL = true == identifier?.hasPrefix("org.cocoapods") ? bundle.url(forResource: name, withExtension: "ttf", subdirectory: "io.cosmicmind.material.fonts.bundle") : bundle.url(forResource: name, withExtension: "ttf")
if let v = fontURL { if let v = fontURL {
let data = NSData(contentsOf: v as URL)! let data = NSData(contentsOf: v as URL)!
...@@ -95,9 +95,9 @@ private class FontLoader { ...@@ -95,9 +95,9 @@ private class FontLoader {
var error: Unmanaged<CFError>? var error: Unmanaged<CFError>?
if !CTFontManagerRegisterGraphicsFont(font, &error) { if !CTFontManagerRegisterGraphicsFont(font, &error) {
let errorDescription: CFString = CFErrorCopyDescription(error!.takeUnretainedValue()) let errorDescription = CFErrorCopyDescription(error!.takeUnretainedValue())
let nsError: NSError = error!.takeUnretainedValue() as AnyObject as! NSError let nsError = error!.takeUnretainedValue() as AnyObject as! Error
NSException(name: .internalInconsistencyException, reason: errorDescription as String, userInfo: [NSUnderlyingErrorKey: nsError]).raise() NSException(name: .internalInconsistencyException, reason: errorDescription as? String, userInfo: [NSUnderlyingErrorKey: nsError as AnyObject]).raise()
} }
} }
} }
......
...@@ -42,12 +42,10 @@ public struct Icon { ...@@ -42,12 +42,10 @@ public struct Icon {
if nil == Icon.internalBundle { if nil == Icon.internalBundle {
Icon.internalBundle = Bundle(for: View.self) Icon.internalBundle = Bundle(for: View.self)
let url = Icon.internalBundle!.resourceURL! let url = Icon.internalBundle!.resourceURL!
do { let b = Bundle(url: url.appendingPathComponent("io.cosmicmind.material.icons.bundle"))
let b = Bundle(url: try url.appendingPathComponent("io.cosmicmind.material.icons.bundle")) if let v = b {
if let v = b { Icon.internalBundle = v
Icon.internalBundle = v }
}
} catch {}
} }
return Icon.internalBundle! return Icon.internalBundle!
} }
......
...@@ -106,13 +106,13 @@ public extension UIImage { ...@@ -106,13 +106,13 @@ public extension UIImage {
return nil return nil
} }
context.scale(x: 1.0, y: -1.0) context.scaleBy(x: 1.0, y: -1.0)
context.translate(x: 0.0, y: -size.height) context.translateBy(x: 0.0, y: -size.height)
context.setBlendMode(.multiply) context.setBlendMode(.multiply)
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
context.clipToMask(rect, mask: cgImage!) context.clip(to: rect, mask: cgImage!)
color.setFill() color.setFill()
context.fill(rect) context.fill(rect)
...@@ -185,8 +185,8 @@ public extension UIImage { ...@@ -185,8 +185,8 @@ public extension UIImage {
- Parameter completion: A completion block that is executed once the image - Parameter completion: A completion block that is executed once the image
has been retrieved. has been retrieved.
*/ */
public class func contentsOfURL(url: URL, completion: ((image: UIImage?, error: NSError?) -> Void)) { public class func contentsOfURL(url: URL, completion: ((image: UIImage?, error: Error?) -> Void)) {
URLSession.shared.dataTask(with: URLRequest(url: url)) { (data: Data?, response: URLResponse?, error: NSError?) in URLSession.shared.dataTask(with: URLRequest(url: url)) { (data: Data?, response: URLResponse?, error: Error?) in
DispatchQueue.main.async { DispatchQueue.main.async {
if let v = error { if let v = error {
completion(image: nil, error: v) completion(image: nil, error: v)
...@@ -215,25 +215,25 @@ public extension UIImage { ...@@ -215,25 +215,25 @@ public extension UIImage {
// Rotate if Left, Right, or Down. // Rotate if Left, Right, or Down.
switch imageOrientation { switch imageOrientation {
case .down, .downMirrored: case .down, .downMirrored:
transform = transform.translateBy(x: size.width, y: size.height) transform = transform.translatedBy(x: size.width, y: size.height)
transform = transform.rotate(CGFloat(M_PI)) transform = transform.rotated(by: CGFloat(M_PI))
case .left, .leftMirrored: case .left, .leftMirrored:
transform = transform.translateBy(x: size.width, y: 0) transform = transform.translatedBy(x: size.width, y: 0)
transform = transform.rotate(CGFloat(M_PI_2)) transform = transform.rotated(by: CGFloat(M_PI_2))
case .right, .rightMirrored: case .right, .rightMirrored:
transform = transform.translateBy(x: 0, y: size.height) transform = transform.translatedBy(x: 0, y: size.height)
transform = transform.rotate(-CGFloat(M_PI_2)) transform = transform.rotated(by: -CGFloat(M_PI_2))
default:break default:break
} }
// Flip if mirrored. // Flip if mirrored.
switch imageOrientation { switch imageOrientation {
case .upMirrored, .downMirrored: case .upMirrored, .downMirrored:
transform = transform.translateBy(x: size.width, y: 0) transform = transform.translatedBy(x: size.width, y: 0)
transform = transform.scaleBy(x: -1, y: 1) transform = transform.scaledBy(x: -1, y: 1)
case .leftMirrored, .rightMirrored: case .leftMirrored, .rightMirrored:
transform = transform.translateBy(x: size.height, y: 0) transform = transform.translatedBy(x: size.height, y: 0)
transform = transform.scaleBy(x: -1, y: 1) transform = transform.scaledBy(x: -1, y: 1)
default:break default:break
} }
...@@ -242,7 +242,7 @@ public extension UIImage { ...@@ -242,7 +242,7 @@ public extension UIImage {
return nil return nil
} }
context.concatCTM(transform) context.concatenate(transform)
switch imageOrientation { switch imageOrientation {
case .left, .leftMirrored, .right, .rightMirrored: case .left, .leftMirrored, .right, .rightMirrored:
......
...@@ -35,7 +35,7 @@ public class MaterialLabel : UILabel { ...@@ -35,7 +35,7 @@ public class MaterialLabel : UILabel {
/** /**
:name: layerClass :name: layerClass
*/ */
public override class func layerClass() -> AnyClass { public override class var layerClass: AnyClass {
return MaterialTextLayer.self return MaterialTextLayer.self
} }
......
...@@ -52,6 +52,17 @@ public extension UINavigationBar { ...@@ -52,6 +52,17 @@ public extension UINavigationBar {
@IBDesignable @IBDesignable
public class NavigationBar: UINavigationBar { public class NavigationBar: UINavigationBar {
public override var intrinsicContentSize: CGSize {
switch navigationBarStyle {
case .Tiny:
return CGSize(width: Device.width, height: 32)
case .Default:
return CGSize(width: Device.width, height: 44)
case .Medium:
return CGSize(width: Device.width, height: 56)
}
}
/// NavigationBarStyle value. /// NavigationBarStyle value.
public var navigationBarStyle: NavigationBarStyle = .Default public var navigationBarStyle: NavigationBarStyle = .Default
...@@ -145,19 +156,8 @@ public class NavigationBar: UINavigationBar { ...@@ -145,19 +156,8 @@ public class NavigationBar: UINavigationBar {
self.init(frame: CGRect.zero) self.init(frame: CGRect.zero)
} }
public override func intrinsicContentSize() -> CGSize {
switch navigationBarStyle {
case .Tiny:
return CGSize(width: Device.width, height: 32)
case .Default:
return CGSize(width: Device.width, height: 44)
case .Medium:
return CGSize(width: Device.width, height: 56)
}
}
public override func sizeThatFits(_ size: CGSize) -> CGSize { public override func sizeThatFits(_ size: CGSize) -> CGSize {
return intrinsicContentSize() return intrinsicContentSize
} }
public override func layoutSublayers(of layer: CALayer) { public override func layoutSublayers(of layer: CALayer) {
...@@ -200,7 +200,7 @@ public class NavigationBar: UINavigationBar { ...@@ -200,7 +200,7 @@ public class NavigationBar: UINavigationBar {
let columns: Int = g + 1 let columns: Int = g + 1
titleView.frame.origin = CGPoint.zero titleView.frame.origin = CGPoint.zero
titleView.frame.size = intrinsicContentSize() titleView.frame.size = intrinsicContentSize
titleView.grid.views = [] titleView.grid.views = []
titleView.grid.axis.columns = columns titleView.grid.axis.columns = columns
...@@ -209,7 +209,7 @@ public class NavigationBar: UINavigationBar { ...@@ -209,7 +209,7 @@ public class NavigationBar: UINavigationBar {
// leftControls // leftControls
if let v: Array<UIControl> = item.leftControls { if let v: Array<UIControl> = item.leftControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize().width let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
...@@ -229,7 +229,7 @@ public class NavigationBar: UINavigationBar { ...@@ -229,7 +229,7 @@ public class NavigationBar: UINavigationBar {
// rightControls // rightControls
if let v: Array<UIControl> = item.rightControls { if let v: Array<UIControl> = item.rightControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize().width let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
......
...@@ -1022,7 +1022,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele ...@@ -1022,7 +1022,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
isStatusBarHidden = false isStatusBarHidden = false
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
if let s = self { if let s = self {
if let v = UIApplication.shared().keyWindow { if let v = UIApplication.shared.keyWindow {
v.windowLevel = UIWindowLevelNormal v.windowLevel = UIWindowLevelNormal
s.delegate?.navigationDrawerStatusBarHiddenState?(navigationDrawerController: s, hidden: false) s.delegate?.navigationDrawerStatusBarHiddenState?(navigationDrawerController: s, hidden: false)
} }
...@@ -1038,7 +1038,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele ...@@ -1038,7 +1038,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
isStatusBarHidden = true isStatusBarHidden = true
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
if let s = self { if let s = self {
if let v = UIApplication.shared().keyWindow { if let v = UIApplication.shared.keyWindow {
v.windowLevel = UIWindowLevelStatusBar + 1 v.windowLevel = UIWindowLevelStatusBar + 1
s.delegate?.navigationDrawerStatusBarHiddenState?(navigationDrawerController: s, hidden: true) s.delegate?.navigationDrawerStatusBarHiddenState?(navigationDrawerController: s, hidden: true)
} }
......
...@@ -188,7 +188,7 @@ public class PhotoLibrary: NSObject { ...@@ -188,7 +188,7 @@ public class PhotoLibrary: NSObject {
- Parameter completion: An optional completion block. - Parameter completion: An optional completion block.
*/ */
public func fetch(type: PHAssetCollectionType, subtype: PHAssetCollectionSubtype, completion: ([PhotoLibraryDataSource]) -> Void) { public func fetch(type: PHAssetCollectionType, subtype: PHAssetCollectionSubtype, completion: ([PhotoLibraryDataSource]) -> Void) {
DispatchQueue.global(attributes: DispatchQueue.GlobalAttributes.qosDefault).async { [weak self, type = type, subtype = subtype, completion = completion] in DispatchQueue.global(qos: .default).async { [weak self, type = type, subtype = subtype, completion = completion] in
guard let s = self else { guard let s = self else {
return return
} }
...@@ -211,7 +211,7 @@ public class PhotoLibrary: NSObject { ...@@ -211,7 +211,7 @@ public class PhotoLibrary: NSObject {
} }
let options = PHFetchOptions() let options = PHFetchOptions()
let descriptor = SortDescriptor(key: "creationDate", ascending: false) let descriptor = NSSortDescriptor(key: "creationDate", ascending: false)
options.sortDescriptors = [descriptor] options.sortDescriptors = [descriptor]
options.includeHiddenAssets = true options.includeHiddenAssets = true
options.includeAllBurstAssets = true options.includeAllBurstAssets = true
...@@ -263,7 +263,7 @@ public class PhotoLibrary: NSObject { ...@@ -263,7 +263,7 @@ public class PhotoLibrary: NSObject {
- Parameter completion: A completion block that is executed once the - Parameter completion: A completion block that is executed once the
transaction has been completed. transaction has been completed.
*/ */
public func performChanges(_ block: () -> Void, completion: ((Bool, NSError?) -> Void)? = nil) { public func performChanges(_ block: () -> Void, completion: ((Bool, Error?) -> Void)? = nil) {
PHPhotoLibrary.shared().performChanges(block, completionHandler: completion) PHPhotoLibrary.shared().performChanges(block, completionHandler: completion)
} }
......
...@@ -71,7 +71,7 @@ public class SearchBar: BarView { ...@@ -71,7 +71,7 @@ public class SearchBar: BarView {
@IBInspectable public var placeholder: String? { @IBInspectable public var placeholder: String? {
didSet { didSet {
if let v: String = placeholder { if let v: String = placeholder {
textField.attributedPlaceholder = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor]) textField.attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
} }
} }
} }
...@@ -80,7 +80,7 @@ public class SearchBar: BarView { ...@@ -80,7 +80,7 @@ public class SearchBar: BarView {
@IBInspectable public var placeholderColor: UIColor = Color.darkText.others { @IBInspectable public var placeholderColor: UIColor = Color.darkText.others {
didSet { didSet {
if let v: String = placeholder { if let v: String = placeholder {
textField.attributedPlaceholder = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor]) textField.attributedPlaceholder = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
} }
} }
} }
......
...@@ -64,7 +64,7 @@ public class SearchBarController: RootController { ...@@ -64,7 +64,7 @@ public class SearchBarController: RootController {
let h: CGFloat = Device.height let h: CGFloat = Device.height
let w: CGFloat = Device.width let w: CGFloat = Device.width
let p: CGFloat = v.intrinsicContentSize().height + v.grid.layoutInset.top + v.grid.layoutInset.bottom let p: CGFloat = v.intrinsicContentSize.height + v.grid.layoutInset.top + v.grid.layoutInset.bottom
v.width = w + v.grid.layoutInset.left + v.grid.layoutInset.right v.width = w + v.grid.layoutInset.left + v.grid.layoutInset.right
v.height = p v.height = p
......
...@@ -244,6 +244,17 @@ public class Switch: UIControl { ...@@ -244,6 +244,17 @@ public class Switch: UIControl {
layoutSwitch() layoutSwitch()
} }
} }
public override var intrinsicContentSize: CGSize {
switch switchSize {
case .small:
return CGSize(width: 30, height: 25)
case .medium:
return CGSize(width: 40, height: 30)
case .large:
return CGSize(width: 50, height: 40)
}
}
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
...@@ -300,17 +311,6 @@ public class Switch: UIControl { ...@@ -300,17 +311,6 @@ public class Switch: UIControl {
styleForState(state: internalSwitchState) styleForState(state: internalSwitchState)
} }
public override func intrinsicContentSize() -> CGSize {
switch switchSize {
case .small:
return CGSize(width: 30, height: 25)
case .medium:
return CGSize(width: 40, height: 30)
case .large:
return CGSize(width: 50, height: 40)
}
}
/** /**
Toggle the Switch state, if On will be Off, and if Off will be On. Toggle the Switch state, if On will be Off, and if Off will be On.
- Parameter completion: An Optional completion block. - Parameter completion: An Optional completion block.
......
...@@ -62,7 +62,7 @@ public protocol TextDelegate { ...@@ -62,7 +62,7 @@ public protocol TextDelegate {
publishing or resolving. publishing or resolving.
*/ */
@objc @objc
optional func textDidProcessEdit(text: Text, textStorage: TextStorage, string: String, result: TextCheckingResult?, flags: RegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) optional func textDidProcessEdit(text: Text, textStorage: TextStorage, string: String, result: NSTextCheckingResult?, flags: NSRegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>)
} }
@objc(Text) @objc(Text)
...@@ -113,7 +113,7 @@ public class Text : NSObject { ...@@ -113,7 +113,7 @@ public class Text : NSObject {
/// Prepares the TextStorage regular expression for matching. /// Prepares the TextStorage regular expression for matching.
private func prepareTextStorageExpression() { private func prepareTextStorageExpression() {
textStorage.expression = try? RegularExpression(pattern: pattern, options: []) textStorage.expression = try? NSRegularExpression(pattern: pattern, options: [])
} }
/// Prepares the pre and post processing callbacks. /// Prepares the pre and post processing callbacks.
...@@ -123,7 +123,7 @@ public class Text : NSObject { ...@@ -123,7 +123,7 @@ public class Text : NSObject {
s.delegate?.textWillProcessEdit?(text: s, textStorage: textStorage, string: string, range: range) s.delegate?.textWillProcessEdit?(text: s, textStorage: textStorage, string: string, range: range)
} }
} }
textStorage.textDidProcessEdit = { [weak self] (textStorage: TextStorage, result: TextCheckingResult?, flags: RegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in textStorage.textDidProcessEdit = { [weak self] (textStorage: TextStorage, result: NSTextCheckingResult?, flags: NSRegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
if let s: Text = self { if let s: Text = self {
s.delegate?.textDidProcessEdit?(text: s, textStorage: textStorage, string: textStorage.string, result: result, flags: flags, stop: stop) s.delegate?.textDidProcessEdit?(text: s, textStorage: textStorage, string: textStorage.string, result: result, flags: flags, stop: stop)
} }
......
...@@ -34,7 +34,12 @@ public protocol TextFieldDelegate: UITextFieldDelegate {} ...@@ -34,7 +34,12 @@ public protocol TextFieldDelegate: UITextFieldDelegate {}
@IBDesignable @IBDesignable
public class TextField: UITextField { public class TextField: UITextField {
/// A Boolean that indicates if the TextField is in an animating state. /// Default size when using AutoLayout.
public override var intrinsicContentSize: CGSize {
return CGSize(width: width, height: 32)
}
/// A Boolean that indicates if the TextField is in an animating state.
public private(set) var animating: Bool = false public private(set) var animating: Bool = false
/// A property that accesses the backing layer's backgroundColor. /// A property that accesses the backing layer's backgroundColor.
...@@ -83,7 +88,7 @@ public class TextField: UITextField { ...@@ -83,7 +88,7 @@ public class TextField: UITextField {
/// TextField's text property observer. /// TextField's text property observer.
@IBInspectable public override var text: String? { @IBInspectable public override var text: String? {
didSet { didSet {
if true == text?.isEmpty && !isFirstResponder() { if true == text?.isEmpty && !isFirstResponder {
placeholderEditingDidEndAnimation() placeholderEditingDidEndAnimation()
} }
} }
...@@ -97,7 +102,7 @@ public class TextField: UITextField { ...@@ -97,7 +102,7 @@ public class TextField: UITextField {
set(value) { set(value) {
placeholderLabel.text = value placeholderLabel.text = value
if let v: String = value { if let v: String = value {
placeholderLabel.attributedText = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor]) placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
} }
} }
} }
...@@ -110,7 +115,7 @@ public class TextField: UITextField { ...@@ -110,7 +115,7 @@ public class TextField: UITextField {
didSet { didSet {
if !isEditing { if !isEditing {
if let v: String = placeholder { if let v: String = placeholder {
placeholderLabel.attributedText = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor]) placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderColor])
} }
} }
} }
...@@ -121,7 +126,7 @@ public class TextField: UITextField { ...@@ -121,7 +126,7 @@ public class TextField: UITextField {
didSet { didSet {
if isEditing { if isEditing {
if let v: String = placeholder { if let v: String = placeholder {
placeholderLabel.attributedText = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderActiveColor]) placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: placeholderActiveColor])
} }
} }
tintColor = placeholderActiveColor tintColor = placeholderActiveColor
...@@ -143,7 +148,7 @@ public class TextField: UITextField { ...@@ -143,7 +148,7 @@ public class TextField: UITextField {
set(value) { set(value) {
detailLabel.text = value detailLabel.text = value
if let v: String = value { if let v: String = value {
detailLabel.attributedText = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor]) detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
} }
layoutDetailLabel() layoutDetailLabel()
} }
...@@ -153,7 +158,7 @@ public class TextField: UITextField { ...@@ -153,7 +158,7 @@ public class TextField: UITextField {
@IBInspectable public var detailColor: UIColor = Color.darkText.others { @IBInspectable public var detailColor: UIColor = Color.darkText.others {
didSet { didSet {
if let v: String = detailLabel.text { if let v: String = detailLabel.text {
detailLabel.attributedText = AttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor]) detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
} }
} }
} }
...@@ -298,11 +303,6 @@ public class TextField: UITextField { ...@@ -298,11 +303,6 @@ public class TextField: UITextField {
} }
} }
/// Default size when using AutoLayout.
public override func intrinsicContentSize() -> CGSize {
return CGSize(width: width, height: 32)
}
/// Handles the text editing did begin state. /// Handles the text editing did begin state.
public func handleEditingDidBegin() { public func handleEditingDidBegin() {
dividerEditingDidBeginAnimation() dividerEditingDidBeginAnimation()
...@@ -507,6 +507,6 @@ public class TextField: UITextField { ...@@ -507,6 +507,6 @@ public class TextField: UITextField {
/// Prepares the textAlignment. /// Prepares the textAlignment.
private func prepareTextAlignment() { private func prepareTextAlignment() {
textAlignment = .rightToLeft == UIApplication.shared().userInterfaceLayoutDirection ? .right : .left textAlignment = .rightToLeft == UIApplication.shared.userInterfaceLayoutDirection ? .right : .left
} }
} }
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
import UIKit import UIKit
internal typealias TextWillProcessEdit = (TextStorage, String, NSRange) -> Void internal typealias TextWillProcessEdit = (TextStorage, String, NSRange) -> Void
internal typealias TextDidProcessEdit = (TextStorage, TextCheckingResult?, RegularExpression.MatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void internal typealias TextDidProcessEdit = (TextStorage, NSTextCheckingResult?, NSRegularExpression.MatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
public class TextStorage: NSTextStorage { public class TextStorage: NSTextStorage {
/// A callback that is executed when a process edit will happen. /// A callback that is executed when a process edit will happen.
...@@ -44,7 +44,7 @@ public class TextStorage: NSTextStorage { ...@@ -44,7 +44,7 @@ public class TextStorage: NSTextStorage {
public lazy var store: NSMutableAttributedString = NSMutableAttributedString() public lazy var store: NSMutableAttributedString = NSMutableAttributedString()
/// The regular expression to match text fragments against. /// The regular expression to match text fragments against.
public var expression: RegularExpression? public var expression: NSRegularExpression?
/// Initializer. /// Initializer.
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
...@@ -67,7 +67,7 @@ public class TextStorage: NSTextStorage { ...@@ -67,7 +67,7 @@ public class TextStorage: NSTextStorage {
textWillProcessEdit?(self, string, range) textWillProcessEdit?(self, string, range)
expression!.enumerateMatches(in: string, options: [], range: range) { (result: TextCheckingResult?, flags: RegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in expression!.enumerateMatches(in: string, options: [], range: range) { (result: NSTextCheckingResult?, flags: NSRegularExpression.MatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
self.textDidProcessEdit?(self, result, flags, stop) self.textDidProcessEdit?(self, result, flags, stop)
} }
super.processEditing() super.processEditing()
......
...@@ -85,7 +85,7 @@ public class TextView: UITextView { ...@@ -85,7 +85,7 @@ public class TextView: UITextView {
} }
/// An override to the attributedText property. /// An override to the attributedText property.
public override var attributedText: AttributedString! { public override var attributedText: NSAttributedString! {
didSet { didSet {
handleTextViewTextDidChange() handleTextViewTextDidChange()
} }
......
...@@ -167,7 +167,7 @@ public class ToolbarController: RootController { ...@@ -167,7 +167,7 @@ public class ToolbarController: RootController {
let h: CGFloat = Device.height let h: CGFloat = Device.height
let w: CGFloat = Device.width let w: CGFloat = Device.width
let p: CGFloat = v.intrinsicContentSize().height + v.grid.layoutInset.top + v.grid.layoutInset.bottom let p: CGFloat = v.intrinsicContentSize.height + v.grid.layoutInset.top + v.grid.layoutInset.bottom
v.width = w + v.grid.layoutInset.left + v.grid.layoutInset.right v.width = w + v.grid.layoutInset.left + v.grid.layoutInset.right
v.height = p v.height = p
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment