Rename Extensions to UIKit Extensions

This commit is contained in:
Maurice Parker
2019-09-11 16:58:55 -05:00
parent be84fc5a6b
commit 4e83b37c0b
12 changed files with 3 additions and 3 deletions

View File

@@ -0,0 +1,20 @@
//
// Array-Extensions.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 4/28/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
extension Array where Element == CGRect {
func maxY() -> CGFloat {
var y: CGFloat = 0.0
self.forEach { y = Swift.max(y, $0.maxY) }
return y
}
}

View File

@@ -0,0 +1,25 @@
//
// Bundle-Extensions.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 4/26/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import Foundation
extension Bundle {
var appName: String {
return infoDictionary?["CFBundleName"] as! String
}
var versionNumber: String {
return infoDictionary?["CFBundleShortVersionString"] as! String
}
var buildNumber: String {
return infoDictionary?["CFBundleVersion"] as! String
}
}

View File

@@ -0,0 +1,20 @@
//
// NonIntrinsicButton.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 8/25/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import Foundation
import UIKit
class NonIntrinsicButton: UIButton {
// Prevent autolayout from messing around with our frame settings
override var intrinsicContentSize: CGSize {
return CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric)
}
}

View File

@@ -0,0 +1,18 @@
//
// NonIntrinsicImageView.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 4/22/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
class NonIntrinsicImageView: UIImageView {
// Prevent autolayout from messing around with our frame settings
override var intrinsicContentSize: CGSize {
return CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric)
}
}

View File

@@ -0,0 +1,18 @@
//
// MasterTimelineLabel.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 4/22/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
class NonIntrinsicLabel: UILabel {
// Prevent autolayout from messing around with our frame settings
override var intrinsicContentSize: CGSize {
return CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric)
}
}

View File

@@ -0,0 +1,25 @@
//
// String-Extensions.swift
// NetNewsWire
//
// Created by Maurice Parker on 4/8/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
extension String {
func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)
let boundingBox = self.boundingRect(with: constraintRect, options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [NSAttributedString.Key.font: font], context: nil)
return ceil(boundingBox.height)
}
func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height)
let boundingBox = self.boundingRect(with: constraintRect, options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [NSAttributedString.Key.font: font], context: nil)
return ceil(boundingBox.width)
}
}

View File

@@ -0,0 +1,56 @@
//
// ThemedNavigationController.swift
// NetNewsWire
//
// Created by Maurice Parker on 8/22/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
class ThemedNavigationController: UINavigationController {
static func template() -> UINavigationController {
let navController = ThemedNavigationController()
navController.configure()
return navController
}
static func template(rootViewController: UIViewController) -> UINavigationController {
let navController = ThemedNavigationController(rootViewController: rootViewController)
navController.configure()
return navController
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle {
configure()
}
}
private func configure() {
isToolbarHidden = false
if traitCollection.userInterfaceStyle == .dark {
navigationBar.standardAppearance = UINavigationBarAppearance()
navigationBar.tintColor = view.tintColor
toolbar.standardAppearance = UIToolbarAppearance()
toolbar.tintColor = view.tintColor
} else {
let navigationAppearance = UINavigationBarAppearance()
navigationAppearance.backgroundColor = AppAssets.barBackgroundColor
navigationAppearance.titleTextAttributes = [.foregroundColor: AppAssets.barTitleColor]
navigationAppearance.largeTitleTextAttributes = [.foregroundColor: AppAssets.barTitleColor]
navigationBar.standardAppearance = navigationAppearance
navigationBar.tintColor = AppAssets.barTintColor
let toolbarAppearance = UIToolbarAppearance()
toolbarAppearance.backgroundColor = UIColor.white
toolbar.standardAppearance = toolbarAppearance
toolbar.tintColor = AppAssets.barTintColor
}
}
}

View File

@@ -0,0 +1,46 @@
//
// UIBarButtonItem-Extensions.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 4/27/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
public extension UIBarButtonItem {
@IBInspectable var accEnabled: Bool {
get {
return isAccessibilityElement
}
set {
isAccessibilityElement = newValue
}
}
@IBInspectable var accLabelText: String? {
get {
return accessibilityLabel
}
set {
accessibilityLabel = newValue
}
}
var isHidden: Bool {
get {
return tintColor == UIColor.clear
}
set(hide) {
if hide {
isEnabled = false
tintColor = UIColor.clear
} else {
isEnabled = true
tintColor = nil
}
}
}
}

View File

@@ -0,0 +1,26 @@
//
// UIFont-Extensions.swift
// NetNewsWire-iOS
//
// Created by Maurice Parker on 4/27/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
extension UIFont {
func withTraits(traits:UIFontDescriptor.SymbolicTraits) -> UIFont {
let descriptor = fontDescriptor.withSymbolicTraits(traits)
return UIFont(descriptor: descriptor!, size: 0) //size 0 means keep the size as it is
}
func bold() -> UIFont {
return withTraits(traits: .traitBold)
}
func italic() -> UIFont {
return withTraits(traits: .traitItalic)
}
}

View File

@@ -0,0 +1,20 @@
//
// UISplitViewController-Extensions.swift
// NetNewsWire
//
// Created by Maurice Parker on 4/18/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
extension UISplitViewController {
static func template() -> UISplitViewController {
let splitViewController = UISplitViewController()
splitViewController.preferredDisplayMode = .automatic
splitViewController.viewControllers = [ThemedNavigationController.template()]
return splitViewController
}
}

View File

@@ -0,0 +1,37 @@
//
// UIStoryboard-Extensions.swift
// NetNewsWire
//
// Created by Maurice Parker on 4/8/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import UIKit
extension UIStoryboard {
static var main: UIStoryboard {
return UIStoryboard(name: "Main", bundle: nil)
}
static var add: UIStoryboard {
return UIStoryboard(name: "Add", bundle: nil)
}
static var settings: UIStoryboard {
return UIStoryboard(name: "Settings", bundle: nil)
}
func instantiateController<T>(ofType type: T.Type = T.self) -> T where T: UIViewController {
let storyboardId = String(describing: type)
guard let viewController = instantiateViewController(withIdentifier: storyboardId) as? T else {
print("Unable to load view with Scene Identifier: \(storyboardId)")
fatalError()
}
return viewController
}
}