mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Rename Extensions to UIKit Extensions
This commit is contained in:
20
iOS/UIKit Extensions/Array-Extensions.swift
Normal file
20
iOS/UIKit Extensions/Array-Extensions.swift
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
25
iOS/UIKit Extensions/Bundle-Extensions.swift
Normal file
25
iOS/UIKit Extensions/Bundle-Extensions.swift
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
20
iOS/UIKit Extensions/NonIntrinsicButton.swift
Normal file
20
iOS/UIKit Extensions/NonIntrinsicButton.swift
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
18
iOS/UIKit Extensions/NonIntrinsicImageView.swift
Normal file
18
iOS/UIKit Extensions/NonIntrinsicImageView.swift
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
18
iOS/UIKit Extensions/NonIntrinsicLabel.swift
Normal file
18
iOS/UIKit Extensions/NonIntrinsicLabel.swift
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
25
iOS/UIKit Extensions/String-Extensions.swift
Normal file
25
iOS/UIKit Extensions/String-Extensions.swift
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
56
iOS/UIKit Extensions/ThemedNavigationController.swift
Normal file
56
iOS/UIKit Extensions/ThemedNavigationController.swift
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
46
iOS/UIKit Extensions/UIBarButtonItem-Extensions.swift
Normal file
46
iOS/UIKit Extensions/UIBarButtonItem-Extensions.swift
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
26
iOS/UIKit Extensions/UIFont-Extensions.swift
Normal file
26
iOS/UIKit Extensions/UIFont-Extensions.swift
Normal 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)
|
||||
}
|
||||
|
||||
}
|
||||
20
iOS/UIKit Extensions/UISplitViewController-Extensions.swift
Normal file
20
iOS/UIKit Extensions/UISplitViewController-Extensions.swift
Normal 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
|
||||
}
|
||||
|
||||
}
|
||||
37
iOS/UIKit Extensions/UIStoryboard-Extensions.swift
Normal file
37
iOS/UIKit Extensions/UIStoryboard-Extensions.swift
Normal 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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user