diff --git a/README.md b/README.md
index 3965e8f..ce0403e 100644
--- a/README.md
+++ b/README.md
@@ -23,16 +23,19 @@ TinyConsoleController(rootViewController: MyMainViewController())
### Actions
```swift
-// TinyConsole prints NSFormattedStrings and Strings
+// Print message
TinyConsole.print("hello")
-// print messages any color you want
+// Print messages any color you want
TinyConsole.print("green text", color: UIColor.green)
-// prints a red error message
+// Print a red error message
TinyConsole.error("something went wrong")
+// Print a marker for orientation
TinyConsole.addMarker()
+
+// Clear console
TinyConsole.clear()
```
@@ -50,9 +53,9 @@ Instead of
```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
- self.window = UIWindow(frame: UIScreen.main.bounds)
- self.window?.rootViewController = MainViewController()
- self.window?.makeKeyAndVisible()
+ window = UIWindow(frame: UIScreen.main.bounds)
+ window?.rootViewController = MainViewController()
+ window?.makeKeyAndVisible()
return true
}
```
@@ -61,9 +64,9 @@ write
```swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
- self.window = UIWindow(frame: UIScreen.main.bounds)
- self.window?.rootViewController = TinyConsoleController(rootViewController: MainViewController())
- self.window?.makeKeyAndVisible()
+ window = UIWindow(frame: UIScreen.main.bounds)
+ window?.rootViewController = TinyConsoleController(rootViewController: MainViewController())
+ window?.makeKeyAndVisible()
return true
}
```
@@ -74,6 +77,12 @@ or checkout the example project included in this repository.
+## Requirements
+
+* Xcode 8
+* Swift 3
+* iOS 8 or greater
+
## Installation
### [Carthage](https://github.com/Carthage/Carthage)
diff --git a/TinyConsole-Example/AppDelegate.swift b/TinyConsole-Example/AppDelegate.swift
index 7d4037f..45730c2 100644
--- a/TinyConsole-Example/AppDelegate.swift
+++ b/TinyConsole-Example/AppDelegate.swift
@@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
- self.window = UIWindow(frame: UIScreen.main.bounds)
+ window = UIWindow(frame: UIScreen.main.bounds)
let viewController = UINavigationController(rootViewController: MainViewController())
viewController.title = "Main"
@@ -25,8 +25,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
viewController
]
- self.window?.rootViewController = TinyConsoleController(rootViewController: tabBarController)
- self.window?.makeKeyAndVisible()
+ window?.rootViewController = TinyConsoleController(rootViewController: tabBarController)
+ window?.makeKeyAndVisible()
return true
}
diff --git a/TinyConsole-Example/DataSource.swift b/TinyConsole-Example/DataSource.swift
new file mode 100644
index 0000000..84c46bf
--- /dev/null
+++ b/TinyConsole-Example/DataSource.swift
@@ -0,0 +1,29 @@
+//
+// DataSource.swift
+// TinyConsole
+//
+// Created by Devran Uenal on 11.12.16.
+//
+//
+
+import UIKit
+
+class MainTableViewDataSource: NSObject, UITableViewDataSource {
+ func registerCellsForTableView(_ tableView: UITableView) {
+ tableView.register(UITableViewCell.self, forCellReuseIdentifier: "default")
+ }
+
+ func numberOfSections(in tableView: UITableView) -> Int {
+ return 1
+ }
+
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+ return 30
+ }
+
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+ let cell = tableView.dequeueReusableCell(withIdentifier: "default", for: indexPath)
+ cell.textLabel?.text = "Row \(indexPath.row)"
+ return cell
+ }
+}
diff --git a/TinyConsole-Example/Delegate.swift b/TinyConsole-Example/Delegate.swift
new file mode 100644
index 0000000..e3a5510
--- /dev/null
+++ b/TinyConsole-Example/Delegate.swift
@@ -0,0 +1,16 @@
+//
+// Delegate.swift
+// TinyConsole
+//
+// Created by Devran Uenal on 11.12.16.
+//
+//
+
+import UIKit
+import TinyConsole
+
+class MainTableViewDelegate: NSObject, UITableViewDelegate {
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+ TinyConsole.print("Tapped on \(indexPath.row)")
+ }
+}
diff --git a/TinyConsole-Example/MainViewController.swift b/TinyConsole-Example/MainViewController.swift
index 8c68910..f1c4333 100644
--- a/TinyConsole-Example/MainViewController.swift
+++ b/TinyConsole-Example/MainViewController.swift
@@ -10,41 +10,55 @@ import UIKit
import TinyConsole
class MainViewController: UITableViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- self.view.backgroundColor = UIColor.white
-
- self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "default")
-
- self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Add Log", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addLog))
- self.navigationItem.rightBarButtonItems = [
- UIBarButtonItem(title: "Add Marker", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addMarker)),
- UIBarButtonItem(title: "Clear", style: UIBarButtonItemStyle.plain, target: self, action: #selector(clear)),
- ]
- }
+ var tableViewDelegate: UITableViewDelegate
+ var tableViewDataSource: UITableViewDataSource
- override func numberOfSections(in tableView: UITableView) -> Int {
- return 1
+ init() {
+ tableViewDelegate = MainTableViewDelegate()
+ tableViewDataSource = MainTableViewDataSource()
+ super.init(style: UITableViewStyle.plain)
}
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 30
+ required init?(coder aDecoder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
}
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = self.tableView.dequeueReusableCell(withIdentifier: "default", for: indexPath)
+ override func viewDidLoad() {
+ (tableViewDataSource as? MainTableViewDataSource)?.registerCellsForTableView(self.tableView)
+ tableView.delegate = tableViewDelegate
+ tableView.dataSource = tableViewDataSource
- cell.textLabel?.text = "Row \(indexPath.row)"
+ super.viewDidLoad()
+ view.backgroundColor = UIColor.white
- return cell
+ setupNavigationItems()
}
-
- override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- TinyConsole.print("Tapped on \(indexPath.row)")
+
+ override func viewDidAppear(_ animated: Bool) {
+ super.viewDidAppear(animated)
+
+ TinyConsole.print("Welcome to TinyConsole")
+ TinyConsole.addMarker()
+ TinyConsole.print("NOW", color: UIColor.red)
+ TinyConsole.print("IN", color: UIColor.green)
+ TinyConsole.print("COLOR", color: UIColor.blue)
+ TinyConsole.addMarker()
}
+ func setupNavigationItems() {
+ navigationItem.leftBarButtonItems = [
+ UIBarButtonItem(title: "Add Log", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addLog))
+ ]
+ navigationItem.rightBarButtonItems = [
+ UIBarButtonItem( title: "Add Marker", style: UIBarButtonItemStyle.plain, target: self, action: #selector(addMarker)),
+ UIBarButtonItem( title: "Clear", style: UIBarButtonItemStyle.plain, target: self, action: #selector(clear)),
+ ]
+ }
+}
+
+extension MainViewController {
func addLog() {
- TinyConsole.print("hello world")
+ TinyConsole.print("Hello World")
}
func clear() {
@@ -55,4 +69,3 @@ class MainViewController: UITableViewController {
TinyConsole.addMarker()
}
}
-
diff --git a/TinyConsole.podspec b/TinyConsole.podspec
index 34bcb2d..a97b42d 100644
--- a/TinyConsole.podspec
+++ b/TinyConsole.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TinyConsole'
- s.version = '1.2.1'
+ s.version = '1.3.1'
s.summary = 'A tiny log console to display information while using your iOS app. Written in Swift 3.'
s.description = <<-DESC
diff --git a/TinyConsole.xcodeproj/project.pbxproj b/TinyConsole.xcodeproj/project.pbxproj
index 2c67ddf..58c664b 100644
--- a/TinyConsole.xcodeproj/project.pbxproj
+++ b/TinyConsole.xcodeproj/project.pbxproj
@@ -7,6 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
+ 450284DE1DFD878C00922381 /* DataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 450284DD1DFD878C00922381 /* DataSource.swift */; };
+ 450284E01DFD87BA00922381 /* Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 450284DF1DFD87BA00922381 /* Delegate.swift */; };
457B894F1DF4DB74001DD49C /* TinyConsole.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4585FDCB1DEC54B800DDF5EB /* TinyConsole.framework */; };
457B89501DF4DB74001DD49C /* TinyConsole.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4585FDCB1DEC54B800DDF5EB /* TinyConsole.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
4585FDD81DEC54D300DDF5EB /* TinyConsole.h in Headers */ = {isa = PBXBuildFile; fileRef = 4585FDD61DEC54D300DDF5EB /* TinyConsole.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -44,6 +46,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
+ 450284DD1DFD878C00922381 /* DataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataSource.swift; sourceTree = ""; };
+ 450284DF1DFD87BA00922381 /* Delegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Delegate.swift; sourceTree = ""; };
4585FDCB1DEC54B800DDF5EB /* TinyConsole.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TinyConsole.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4585FDD51DEC54D300DDF5EB /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
4585FDD61DEC54D300DDF5EB /* TinyConsole.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TinyConsole.h; sourceTree = ""; };
@@ -120,6 +124,8 @@
children = (
4585FDE51DEC58BB00DDF5EB /* AppDelegate.swift */,
4585FDE71DEC58BB00DDF5EB /* MainViewController.swift */,
+ 450284DD1DFD878C00922381 /* DataSource.swift */,
+ 450284DF1DFD87BA00922381 /* Delegate.swift */,
4585FDEC1DEC58BB00DDF5EB /* Assets.xcassets */,
4585FDEE1DEC58BB00DDF5EB /* LaunchScreen.storyboard */,
4585FDF11DEC58BB00DDF5EB /* Info.plist */,
@@ -251,6 +257,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 450284E01DFD87BA00922381 /* Delegate.swift in Sources */,
+ 450284DE1DFD878C00922381 /* DataSource.swift in Sources */,
4585FDE81DEC58BB00DDF5EB /* MainViewController.swift in Sources */,
4585FDE61DEC58BB00DDF5EB /* AppDelegate.swift in Sources */,
);
diff --git a/TinyConsole/Supporting Files/Info.plist b/TinyConsole/Supporting Files/Info.plist
index fbe1e6b..9f9016a 100644
--- a/TinyConsole/Supporting Files/Info.plist
+++ b/TinyConsole/Supporting Files/Info.plist
@@ -15,7 +15,7 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 1.0
+ 1.3.1
CFBundleVersion
$(CURRENT_PROJECT_VERSION)
NSPrincipalClass
diff --git a/TinyConsole/TinyConsole.swift b/TinyConsole/TinyConsole.swift
index d3a7148..716a6cb 100644
--- a/TinyConsole/TinyConsole.swift
+++ b/TinyConsole/TinyConsole.swift
@@ -12,7 +12,9 @@ open class TinyConsole {
public static var shared = TinyConsole()
var textView: UITextView?
- public static var textAppearance = [NSFontAttributeName : UIFont(name: "Menlo", size: 12.0)!, NSForegroundColorAttributeName : UIColor.white]
+ public static var textAppearance = [
+ NSFontAttributeName: UIFont(name: "Menlo", size: 12.0)!,
+ NSForegroundColorAttributeName: UIColor.white]
private init() {
}
@@ -25,7 +27,7 @@ open class TinyConsole {
}()
func currentTimeStamp() -> String {
- return self.dateFormatter.string(from: Date())
+ return dateFormatter.string(from: Date())
}
public static func scrollToBottom() {
@@ -36,7 +38,7 @@ open class TinyConsole {
}
}
- public static func print(_ text: String, global: Bool = true, color : UIColor = UIColor.white) {
+ public static func print(_ text: String, color: UIColor = UIColor.white, global: Bool = true) {
let formattedText = NSMutableAttributedString(string: text)
let range = NSRange(location: 0, length: formattedText.length)
@@ -47,21 +49,21 @@ open class TinyConsole {
TinyConsole.print(formattedText, global: global)
}
- public static func print(_ text: NSAttributedString, global : Bool = true) {
+ public static func print(_ text: NSAttributedString, global: Bool = true) {
if let textView = shared.textView {
- let timeStamped = NSMutableAttributedString(string: shared.currentTimeStamp() + " ")
- let range = NSRange(location: 0, length: timeStamped.length)
+ DispatchQueue.main.async {
+ let timeStamped = NSMutableAttributedString(string: shared.currentTimeStamp() + " ")
+ let range = NSRange(location: 0, length: timeStamped.length)
- // set standard text appearance for time-stamp
- timeStamped.addAttributes(TinyConsole.textAppearance, range: range)
-
- timeStamped.append(text)
- timeStamped.append(NSAttributedString(string :"\n"))
+ // set standard text appearance for time-stamp
+ timeStamped.addAttributes(TinyConsole.textAppearance, range: range)
- let newText = NSMutableAttributedString(attributedString: textView.attributedText)
- newText.append(timeStamped)
+ timeStamped.append(text)
+ timeStamped.append(NSAttributedString(string: "\n"))
+
+ let newText = NSMutableAttributedString(attributedString: textView.attributedText)
+ newText.append(timeStamped)
- DispatchQueue.main.async {
textView.attributedText = newText
TinyConsole.scrollToBottom()
}
diff --git a/TinyConsole/TinyConsoleController.swift b/TinyConsole/TinyConsoleController.swift
index e81d27d..2b8fa5e 100644
--- a/TinyConsole/TinyConsoleController.swift
+++ b/TinyConsole/TinyConsoleController.swift
@@ -8,110 +8,178 @@
import UIKit
-enum TinyConsoleWindowMode {
- case collapsed
- case expanded
-}
-
open class TinyConsoleController: UIViewController {
- var rootViewController: UIViewController?
- var consoleViewController: TinyConsoleViewController = {
+ /// the kind of window modes that are supported by TinyConsole
+ ///
+ /// - collapsed: the console is hidden
+ /// - expanded: the console is shown
+ enum WindowMode {
+ case collapsed
+ case expanded
+ }
+
+ // MARK: - Private Properties -
+ private var rootViewController: UIViewController
+
+ private var consoleViewController: TinyConsoleViewController = {
return TinyConsoleViewController()
}()
- var consoleWindowMode: TinyConsoleWindowMode = .collapsed {
+ private lazy var consoleViewHeightConstraint: NSLayoutConstraint? = {
+ if #available(iOS 9, *) {
+ return self.consoleViewController.view.heightAnchor.constraint(equalToConstant: 0)
+ } else {
+ return NSLayoutConstraint(item: self.consoleViewController.view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 0)
+ }
+ }()
+
+ private let consoleFrameHeight: CGFloat = 120
+ private let expandedHeight: CGFloat = 140
+
+ private lazy var consoleFrame: CGRect = {
+
+ var consoleFrame = self.view.bounds
+ consoleFrame.size.height -= self.consoleFrameHeight
+
+ return consoleFrame
+ }()
+
+ private var consoleWindowMode: WindowMode = .collapsed {
didSet {
- self.consoleViewHeightConstraint?.isActive = false
- self.consoleViewHeightConstraint?.constant = self.consoleWindowMode == .collapsed ? 0 : 140
- self.consoleViewHeightConstraint?.isActive = true
+ consoleViewHeightConstraint?.isActive = false
+ consoleViewHeightConstraint?.constant = consoleWindowMode == .collapsed ? 0 : self.expandedHeight
+ consoleViewHeightConstraint?.isActive = true
}
}
+ // MARK: - Initializer -
public init(rootViewController: UIViewController) {
self.rootViewController = rootViewController
super.init(nibName: nil, bundle: nil)
}
required public init?(coder aDecoder: NSCoder) {
+ assertionFailure("Interface Builder is not supported")
+ self.rootViewController = UIViewController()
super.init(coder: aDecoder)
}
+ // MARK: - Public Methods -
override open func viewDidLoad() {
super.viewDidLoad()
- var consoleFrame = self.view.bounds
- consoleFrame.size.height = self.view.bounds.height - 120
+ addChildViewController(consoleViewController)
+ consoleViewController.view.frame = consoleFrame
+ view.addSubview(consoleViewController.view)
+ consoleViewController.didMove(toParentViewController: self)
- self.addChildViewController(self.consoleViewController)
- self.consoleViewController.view.frame = consoleFrame
- self.view.addSubview(self.consoleViewController.view)
- self.consoleViewController.didMove(toParentViewController: self)
+ addChildViewController(rootViewController)
+ rootViewController.view.frame = CGRect(x: consoleFrame.minX, y: consoleFrame.maxY, width: view.bounds.width, height: 120)
+ view.addSubview(rootViewController.view)
+ rootViewController.didMove(toParentViewController: self)
- if let content = self.rootViewController {
- self.addChildViewController(content)
- content.view.frame = CGRect(x: consoleFrame.minX, y: consoleFrame.maxY, width: self.view.bounds.width, height: 120)
- self.view.addSubview(content.view)
- content.didMove(toParentViewController: self)
- }
-
- self.setupConstraints()
+ setupConstraints()
}
- lazy var consoleViewHeightConstraint: NSLayoutConstraint? = {
- if #available(iOS 9, *) {
- return self.consoleViewController.view.heightAnchor.constraint(equalToConstant: 0)
- } else {
- return NSLayoutConstraint(item: self.consoleViewController.view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 0)
+ open override func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
+ if (motion == UIEventSubtype.motionShake) {
+ consoleWindowMode = consoleWindowMode == .collapsed ? .expanded : .collapsed
+ UIView.animate(withDuration: 0.25) {
+ self.view.layoutIfNeeded()
+ }
}
- }()
+ }
- func setupConstraints() {
+ // MARK: - Private Methods -
+ private func setupConstraints() {
+
+ rootViewController.view.attach(anchor: .top, to: view)
+
+ consoleViewController.view.attach(anchor: .bottom, to: view)
+ consoleViewHeightConstraint?.isActive = true
+
if #available(iOS 9, *) {
- self.rootViewController?.view.translatesAutoresizingMaskIntoConstraints = false
- self.rootViewController?.view.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
- self.rootViewController?.view.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
- self.rootViewController?.view.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
-
- self.consoleViewController.view.translatesAutoresizingMaskIntoConstraints = false
- self.consoleViewController.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
- self.consoleViewController.view.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
- self.consoleViewController.view.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
-
- self.consoleViewHeightConstraint?.isActive = true
- self.rootViewController?.view.bottomAnchor.constraint(equalTo: self.consoleViewController.view.topAnchor).isActive = true
+ rootViewController.view.bottomAnchor.constraint(equalTo: consoleViewController.view.topAnchor).isActive = true
} else {
- self.rootViewController?.view.translatesAutoresizingMaskIntoConstraints = false
- NSLayoutConstraint(item: (self.rootViewController?.view)!, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
- NSLayoutConstraint(item: (self.rootViewController?.view)!, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: 0).isActive = true
- NSLayoutConstraint(item: (self.rootViewController?.view)!, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
- self.consoleViewController.view.translatesAutoresizingMaskIntoConstraints = false
- NSLayoutConstraint(item: self.consoleViewController.view, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true
- NSLayoutConstraint(item: self.consoleViewController.view, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: 0).isActive = true
- NSLayoutConstraint(item: self.consoleViewController.view, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
-
- self.consoleViewHeightConstraint?.isActive = true
-
- NSLayoutConstraint(item: (self.rootViewController?.view)!, attribute: .bottom, relatedBy: .equal, toItem: self.consoleViewController.view, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
+ NSLayoutConstraint(item: (rootViewController.view)!,
+ attribute: .bottom,
+ relatedBy: .equal,
+ toItem: consoleViewController.view,
+ attribute: .top,
+ multiplier: 1.0,
+ constant: 0)
+ .isActive = true
}
}
+}
+
+fileprivate extension UIView {
- open override func updateViewConstraints() {
- super.updateViewConstraints()
+ enum Anchor {
+ case top
+ case bottom
}
- open override func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
- if (motion == UIEventSubtype.motionShake) {
- self.consoleWindowMode = self.consoleWindowMode == .collapsed ? .expanded : .collapsed
- UIView.animate(withDuration: 0.25) {
- self.view.layoutIfNeeded()
+ func attach(anchor: Anchor, to view: UIView) {
+
+ translatesAutoresizingMaskIntoConstraints = false
+
+ if #available(iOS 9, *) {
+
+ switch anchor {
+ case .top:
+ topAnchor.constraint(equalTo: view.topAnchor).isActive = true
+ case .bottom:
+ bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
+ }
+
+ leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
+ rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
+
+ } else {
+
+ switch anchor {
+ case .top:
+ NSLayoutConstraint(item: self,
+ attribute: .top,
+ relatedBy: .equal,
+ toItem: view,
+ attribute: .top,
+ multiplier: 1.0,
+ constant: 0)
+ .isActive = true
+ case .bottom:
+ NSLayoutConstraint(item: self,
+ attribute: .bottom,
+ relatedBy: .equal,
+ toItem: view,
+ attribute: .bottom,
+ multiplier: 1.0,
+ constant: 0)
+ .isActive = true
}
+
+ // left anchor
+ NSLayoutConstraint(item: self,
+ attribute: .left,
+ relatedBy: .equal,
+ toItem: view,
+ attribute: .left,
+ multiplier: 1.0,
+ constant: 0)
+ .isActive = true
+ // right anchor
+ NSLayoutConstraint(item: self,
+ attribute: .right,
+ relatedBy: .equal,
+ toItem: view,
+ attribute: .right,
+ multiplier: 1.0,
+ constant: 0)
+ .isActive = true
}
}
-
- open override func motionEnded(_ motion: UIEventSubtype, with event: UIEvent?) {
-
- }
}
diff --git a/TinyConsole/TinyConsoleViewController.swift b/TinyConsole/TinyConsoleViewController.swift
index eafb85d..4556e0d 100644
--- a/TinyConsole/TinyConsoleViewController.swift
+++ b/TinyConsole/TinyConsoleViewController.swift
@@ -19,39 +19,39 @@ class TinyConsoleViewController: UIViewController {
override open func viewDidLoad() {
super.viewDidLoad()
- TinyConsole.shared.textView = self.consoleTextView
- self.view.addSubview(self.consoleTextView)
+ TinyConsole.shared.textView = consoleTextView
+ view.addSubview(consoleTextView)
let addMarkerGesture = UISwipeGestureRecognizer(target: self, action: #selector(addMarker))
- self.view.addGestureRecognizer(addMarkerGesture)
+ view.addGestureRecognizer(addMarkerGesture)
let addCustomTextGesture = UITapGestureRecognizer(target: self, action: #selector(customText))
addCustomTextGesture.numberOfTouchesRequired = 2
if #available(iOS 9, *) {
- self.view.addGestureRecognizer(addCustomTextGesture)
+ view.addGestureRecognizer(addCustomTextGesture)
} else {
- self.consoleTextView.addGestureRecognizer(addCustomTextGesture)
+ consoleTextView.addGestureRecognizer(addCustomTextGesture)
}
let showAdditionalActionsGesture = UITapGestureRecognizer(target: self, action: #selector(additionalActions))
showAdditionalActionsGesture.numberOfTouchesRequired = 3
- self.view.addGestureRecognizer(showAdditionalActionsGesture)
+ view.addGestureRecognizer(showAdditionalActionsGesture)
- self.setupConstraints()
+ setupConstraints()
}
func setupConstraints() {
- self.consoleTextView.translatesAutoresizingMaskIntoConstraints = false
+ consoleTextView.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 9, *) {
- self.consoleTextView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
- self.consoleTextView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
- self.consoleTextView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
- self.consoleTextView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
+ consoleTextView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
+ consoleTextView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
+ consoleTextView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
+ consoleTextView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
} else {
- NSLayoutConstraint(item: self.consoleTextView, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
- NSLayoutConstraint(item: self.consoleTextView, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: 0).isActive = true
- NSLayoutConstraint(item: self.consoleTextView, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
- NSLayoutConstraint(item: self.consoleTextView, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true
+ NSLayoutConstraint(item: consoleTextView, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
+ NSLayoutConstraint(item: consoleTextView, attribute: .left, relatedBy: .equal, toItem: view, attribute: .left, multiplier: 1.0, constant: 0).isActive = true
+ NSLayoutConstraint(item: consoleTextView, attribute: .right, relatedBy: .equal, toItem: view, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
+ NSLayoutConstraint(item: consoleTextView, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true
}
}
@@ -73,7 +73,7 @@ class TinyConsoleViewController: UIViewController {
alert.addAction(okAction)
alert.addAction(cancelAction)
- self.present(alert, animated: true, completion: nil)
+ present(alert, animated: true, completion: nil)
}
func additionalActions(sender: UITapGestureRecognizer) {
@@ -103,7 +103,7 @@ class TinyConsoleViewController: UIViewController {
alert.addAction(clearAction)
alert.addAction(cancelAction)
- self.present(alert, animated: true, completion: nil)
+ present(alert, animated: true, completion: nil)
}
func addMarker(sender: UISwipeGestureRecognizer) {