Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d364aa66b | |||
| 3a18df11ea | |||
| 5f8cba0388 | |||
| 930bc42cef |
@@ -21,20 +21,27 @@ let localConsoleManager = LCManager.shared
|
||||
Once prepared, the localConsole can be used throughout your project.
|
||||
```swift
|
||||
|
||||
// Show local console.
|
||||
// Show the console view.
|
||||
localConsoleManager.isVisible = true
|
||||
|
||||
// Hide local console.
|
||||
// Hide the console view.
|
||||
localConsoleManager.isVisible = false
|
||||
```
|
||||
|
||||
// Print items to local console.
|
||||
```swift
|
||||
// Print items to the console view.
|
||||
localConsoleManager.print("Hello, world!")
|
||||
|
||||
// Clear local console text.
|
||||
// Clear text in the console view.
|
||||
localConsoleManager.clear()
|
||||
```
|
||||
|
||||
```swift
|
||||
// Change the console view font size.
|
||||
localConsoleManager.fontSize = 5
|
||||
```
|
||||
|
||||
|
||||
## **Upcoming Features**
|
||||
* Custom console view size
|
||||
* Custom console view font size
|
||||
* Support for iOS 13
|
||||
|
||||
@@ -16,6 +16,16 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
|
||||
public static let shared = LCManager()
|
||||
|
||||
// Set the font size. The font can be set to a minimum value of 5.0 and a maximum value of 20.0. The default value is 7.5.
|
||||
public var fontSize: CGFloat = 7.5 {
|
||||
didSet {
|
||||
guard fontSize >= 4 else { fontSize = 4; return }
|
||||
guard fontSize <= 20 else { fontSize = 20; return }
|
||||
|
||||
setAttributedText(consoleTextView.text)
|
||||
}
|
||||
}
|
||||
|
||||
let consoleSize = CGSize(width: 212, height: 124)
|
||||
|
||||
// Strong reference needed to keep the window alive.
|
||||
@@ -144,6 +154,8 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
UIView.swizzleDebugBehaviour
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
public var isVisible = false {
|
||||
|
||||
didSet {
|
||||
@@ -166,6 +178,27 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
/// Print items to the console view.
|
||||
public func print(_ items: Any) {
|
||||
|
||||
let string: String = {
|
||||
if consoleTextView.text == "" {
|
||||
return "\(items)"
|
||||
} else {
|
||||
return "\(items)\n" + consoleTextView.text
|
||||
}
|
||||
}()
|
||||
|
||||
setAttributedText(string)
|
||||
}
|
||||
|
||||
/// Clear text in the console view.
|
||||
public func clear() {
|
||||
consoleTextView.text = ""
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private var debugBordersEnabled = false {
|
||||
didSet {
|
||||
GLOBAL_DEBUG_BORDERS = debugBordersEnabled
|
||||
@@ -219,32 +252,19 @@ public class LCManager: NSObject, UIGestureRecognizerDelegate {
|
||||
consoleView.backgroundColor = .black
|
||||
}
|
||||
|
||||
public func print(_ items: Any) {
|
||||
|
||||
func setAttributedText(_ string: String) {
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.headIndent = 7
|
||||
|
||||
let attributes: [NSAttributedString.Key: Any] = [
|
||||
.paragraphStyle: paragraphStyle,
|
||||
.foregroundColor: UIColor.white,
|
||||
.font: UIFont.systemFont(ofSize: 7, weight: .semibold, design: .monospaced)
|
||||
.font: UIFont.systemFont(ofSize: fontSize, weight: .semibold, design: .monospaced)
|
||||
]
|
||||
|
||||
let string: String = {
|
||||
if consoleTextView.attributedText.string == "" {
|
||||
return "\(items)"
|
||||
} else {
|
||||
return "\(items)\n" + consoleTextView.text
|
||||
}
|
||||
}()
|
||||
|
||||
consoleTextView.attributedText = NSAttributedString(string: string, attributes: attributes)
|
||||
}
|
||||
|
||||
public func clear() {
|
||||
consoleTextView.text = ""
|
||||
}
|
||||
|
||||
func makeMenu() -> UIMenu {
|
||||
let viewFrames = UIAction(title: debugBordersEnabled ? "Hide View Frames" : "Show View Frames",
|
||||
image: UIImage(systemName: "rectangle.3.offgrid"), handler: { _ in
|
||||
|
||||
Reference in New Issue
Block a user