Commit 6b7cede3 by Daniel Dahan

editor: added EditorController class

parent 112a20a0
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
961DED461DCC40C500F425B6 /* Editor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961DED451DCC40C500F425B6 /* Editor.swift */; }; 961DED461DCC40C500F425B6 /* Editor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961DED451DCC40C500F425B6 /* Editor.swift */; };
961DED4B1DCC546100F425B6 /* EditorController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961DED4A1DCC546100F425B6 /* EditorController.swift */; };
961EFC581D738FF600E84652 /* SnackbarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961EFC571D738FF600E84652 /* SnackbarController.swift */; }; 961EFC581D738FF600E84652 /* SnackbarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961EFC571D738FF600E84652 /* SnackbarController.swift */; };
961F18E81CD93E3E008927C5 /* ErrorTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961F18E71CD93E3E008927C5 /* ErrorTextField.swift */; }; 961F18E81CD93E3E008927C5 /* ErrorTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961F18E71CD93E3E008927C5 /* ErrorTextField.swift */; };
96230AB81D6A520C00AF47DC /* Divider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96230AB71D6A520C00AF47DC /* Divider.swift */; }; 96230AB81D6A520C00AF47DC /* Divider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96230AB71D6A520C00AF47DC /* Divider.swift */; };
...@@ -205,6 +206,7 @@ ...@@ -205,6 +206,7 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
961DED451DCC40C500F425B6 /* Editor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Editor.swift; sourceTree = "<group>"; }; 961DED451DCC40C500F425B6 /* Editor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Editor.swift; sourceTree = "<group>"; };
961DED4A1DCC546100F425B6 /* EditorController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditorController.swift; sourceTree = "<group>"; };
961EFC571D738FF600E84652 /* SnackbarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnackbarController.swift; sourceTree = "<group>"; }; 961EFC571D738FF600E84652 /* SnackbarController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnackbarController.swift; sourceTree = "<group>"; };
961F18E71CD93E3E008927C5 /* ErrorTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorTextField.swift; sourceTree = "<group>"; }; 961F18E71CD93E3E008927C5 /* ErrorTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorTextField.swift; sourceTree = "<group>"; };
96230AB71D6A520C00AF47DC /* Divider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Divider.swift; sourceTree = "<group>"; }; 96230AB71D6A520C00AF47DC /* Divider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Divider.swift; sourceTree = "<group>"; };
...@@ -361,6 +363,7 @@ ...@@ -361,6 +363,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
961DED451DCC40C500F425B6 /* Editor.swift */, 961DED451DCC40C500F425B6 /* Editor.swift */,
961DED4A1DCC546100F425B6 /* EditorController.swift */,
); );
name = Editor; name = Editor;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1075,6 +1078,7 @@ ...@@ -1075,6 +1078,7 @@
96BCB7A91CB40DC500C806FE /* FlatButton.swift in Sources */, 96BCB7A91CB40DC500C806FE /* FlatButton.swift in Sources */,
96BCB7CA1CB40DC500C806FE /* Layout.swift in Sources */, 96BCB7CA1CB40DC500C806FE /* Layout.swift in Sources */,
96BCB7D11CB40DC500C806FE /* Switch.swift in Sources */, 96BCB7D11CB40DC500C806FE /* Switch.swift in Sources */,
961DED4B1DCC546100F425B6 /* EditorController.swift in Sources */,
96BCB7BA1CB40DC500C806FE /* CollectionView.swift in Sources */, 96BCB7BA1CB40DC500C806FE /* CollectionView.swift in Sources */,
96BCB7BC1CB40DC500C806FE /* CollectionViewDataSource.swift in Sources */, 96BCB7BC1CB40DC500C806FE /* CollectionViewDataSource.swift in Sources */,
96717B191DBE6B1800DA84DB /* PhotoLibraryController.swift in Sources */, 96717B191DBE6B1800DA84DB /* PhotoLibraryController.swift in Sources */,
......
...@@ -49,7 +49,7 @@ extension UIViewController { ...@@ -49,7 +49,7 @@ extension UIViewController {
} }
} }
open class CaptureController: ToolbarController, CaptureDelegate { open class CaptureController: ToolbarController {
/// A reference to the Capture instance. /// A reference to the Capture instance.
@IBInspectable @IBInspectable
open private(set) lazy var capture: Capture = Capture() open private(set) lazy var capture: Capture = Capture()
...@@ -93,7 +93,8 @@ open class CaptureController: ToolbarController, CaptureDelegate { ...@@ -93,7 +93,8 @@ open class CaptureController: ToolbarController, CaptureDelegate {
/// Prepares capture. /// Prepares capture.
private func prepareCapture() { private func prepareCapture() {
capture.delegate = self capture.delegate = self
capture.delegate = self
capture.flashMode = .auto capture.flashMode = .auto
} }
} }
extension CaptureController: CaptureDelegate {}
...@@ -30,78 +30,111 @@ ...@@ -30,78 +30,111 @@
import UIKit import UIKit
public enum CharacterAttributePreset { public enum CharacterAttribute: String {
case font case font = "NSFontAttributeName"
case paragraphStyle case paragraphStyle = "NSParagraphStyleAttributeName"
case forgroundColor case forgroundColor = "NSForegroundColorAttributeName"
case backgroundColor case backgroundColor = "NSBackgroundColorAttributeName"
case ligature case ligature = "NSLigatureAttributeName"
case kern case kern = "NSKernAttributeName"
case strikethroughStyle case strikethroughStyle = "NSStrikethroughStyleAttributeName"
case underlineStyle case underlineStyle = "NSUnderlineStyleAttributeName"
case strokeColor case strokeColor = "NSStrokeColorAttributeName"
case strokeWidth case strokeWidth = "NSStrokeWidthAttributeName"
case shadow case shadow = "NSShadowAttributeName"
case textEffect case textEffect = "NSTextEffectAttributeName"
case attachment case attachment = "NSAttachmentAttributeName"
case baselineOffset case link = "NSLinkAttributeName"
case underlineColor case baselineOffset = "NSBaselineOffsetAttributeName"
case strikethroughColor case underlineColor = "NSUnderlineColorAttributeName"
case obliqueness case strikethroughColor = "NSStrikethroughColorAttributeName"
case expansion case obliqueness = "NSObliquenessAttributeName"
case writingDirection case expansion = "NSExpansionAttributeName"
case verticalGlyphForm case writingDirection = "NSWritingDirectionAttributeName"
case verticalGlyphForm = "NSVerticalGlyphFormAttributeName"
} }
public func CharacterSpacePresetToValue(preset: CharacterAttributePreset) -> String { public func CharacterAttributeToValue(preset: CharacterAttribute) -> String {
// Predefined character attributes for text. If the key is not in the dictionary, then use the default values as described below. switch preset {
/************************ Attributes ************************/ case .font:
@available(iOS 6.0, *) return NSFontAttributeName
public let NSFontAttributeName: String // UIFont, default Helvetica(Neue) 12 case .paragraphStyle:
@available(iOS 6.0, *) return NSParagraphStyleAttributeName
public let NSParagraphStyleAttributeName: String // NSParagraphStyle, default defaultParagraphStyle case .forgroundColor:
@available(iOS 6.0, *) return NSForegroundColorAttributeName
public let NSForegroundColorAttributeName: String // UIColor, default blackColor case .backgroundColor:
@available(iOS 6.0, *) return NSBackgroundColorAttributeName
public let NSBackgroundColorAttributeName: String // UIColor, default nil: no background case .ligature:
@available(iOS 6.0, *) return NSLigatureAttributeName
public let NSLigatureAttributeName: String // NSNumber containing integer, default 1: default ligatures, 0: no ligatures case .kern:
@available(iOS 6.0, *) return NSKernAttributeName
public let NSKernAttributeName: String // NSNumber containing floating point value, in points; amount to modify default kerning. 0 means kerning is disabled. case .strikethroughStyle:
@available(iOS 6.0, *) return NSStrikethroughStyleAttributeName
public let NSStrikethroughStyleAttributeName: String // NSNumber containing integer, default 0: no strikethrough case .underlineStyle:
@available(iOS 6.0, *) return NSUnderlineStyleAttributeName
public let NSUnderlineStyleAttributeName: String // NSNumber containing integer, default 0: no underline case .strokeColor:
@available(iOS 6.0, *) return NSStrokeColorAttributeName
public let NSStrokeColorAttributeName: String // UIColor, default nil: same as foreground color case .strokeWidth:
@available(iOS 6.0, *) return NSStrokeWidthAttributeName
public let NSStrokeWidthAttributeName: String // NSNumber containing floating point value, in percent of font point size, default 0: no stroke; positive for stroke alone, negative for stroke and fill (a typical value for outlined text would be 3.0) case .shadow:
@available(iOS 6.0, *) return NSShadowAttributeName
public let NSShadowAttributeName: String // NSShadow, default nil: no shadow case .textEffect:
@available(iOS 7.0, *) return NSTextEffectAttributeName
public let NSTextEffectAttributeName: String // NSString, default nil: no text effect case .attachment:
return NSAttachmentAttributeName
@available(iOS 7.0, *) case .link:
public let NSAttachmentAttributeName: String // NSTextAttachment, default nil return NSLinkAttributeName
@available(iOS 7.0, *) case .baselineOffset:
public let NSLinkAttributeName: String // NSURL (preferred) or NSString return NSBaselineOffsetAttributeName
@available(iOS 7.0, *) case .underlineColor:
public let NSBaselineOffsetAttributeName: String // NSNumber containing floating point value, in points; offset from baseline, default 0 return NSUnderlineColorAttributeName
@available(iOS 7.0, *) case .strikethroughColor:
public let NSUnderlineColorAttributeName: String // UIColor, default nil: same as foreground color return NSStrikethroughColorAttributeName
@available(iOS 7.0, *) case .obliqueness:
public let NSStrikethroughColorAttributeName: String // UIColor, default nil: same as foreground color return NSObliquenessAttributeName
@available(iOS 7.0, *) case .expansion:
public let NSObliquenessAttributeName: String // NSNumber containing floating point value; skew to be applied to glyphs, default 0: no skew return NSExpansionAttributeName
@available(iOS 7.0, *) case .writingDirection:
public let NSExpansionAttributeName: String // NSNumber containing floating point value; log of expansion factor to be applied to glyphs, default 0: no expansion return NSWritingDirectionAttributeName
case .verticalGlyphForm:
@available(iOS 7.0, *) return NSVerticalGlyphFormAttributeName
public let NSWritingDirectionAttributeName: String // NSArray of NSNumbers representing the nested levels of writing direction overrides as defined by Unicode LRE, RLE, LRO, and RLO characters. The control characters can be obtained by masking NSWritingDirection and NSWritingDirectionFormatType values. LRE: NSWritingDirectionLeftToRight|NSWritingDirectionEmbedding, RLE: NSWritingDirectionRightToLeft|NSWritingDirectionEmbedding, LRO: NSWritingDirectionLeftToRight|NSWritingDirectionOverride, RLO: NSWritingDirectionRightToLeft|NSWritingDirectionOverride, }
}
@available(iOS 6.0, *)
public let NSVerticalGlyphFormAttributeName: String // An NSNumber containing an integer value. 0 means horizontal text. 1 indicates vertical text. If not specified, it could follow higher-level vertical orientation settings. Currently on iOS, it's always horizontal. The behavior for any other value is undefined. /// A memory reference to the CharacterAttribute instance for String extensions.
//private var CharacterAttributeKey: UInt8 = 0
//public struct CharacterAttribute {
//}
//extension String {
/// characterAttribute reference.
// public private(set) var characterAttribute: CharacterAttribute {
// get {
// return AssociatedObject(base: self, key: &CharacterAttributeKey) {
// return CharacterAttribute()
// }
// }
// set(value) {
// AssociateObject(base: self, key: &CharacterAttributeKey, value: value)
// }
// }
//}
extension NSAttributedString {
open func characterAttributes(at index: Int, effectiveRange: NSRangePointer?) -> [CharacterAttribute: Any] {
var ca = [CharacterAttribute: Any]()
attributes(at: index, effectiveRange: effectiveRange).forEach { (key, value) in
guard let attribute = CharacterAttribute.init(rawValue: key) else {
return
}
ca[attribute] = value
}
return ca
}
} }
public enum ParagraphAttribute { public enum ParagraphAttribute {
...@@ -111,3 +144,14 @@ public enum ParagraphAttribute { ...@@ -111,3 +144,14 @@ public enum ParagraphAttribute {
public enum DocumentAttribute { public enum DocumentAttribute {
} }
@objc(EditorDelegate)
public protocol EditorDelegate {
}
open class Editor: View {
/// A reference to an EditorDelegate.
open weak var delegate: EditorDelegate?
}
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.com>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
import AVFoundation
extension UIViewController {
/**
A convenience property that provides access to the EditorController.
This is the recommended method of accessing the EditorController
through child UIViewControllers.
*/
public var editorController: EditorController? {
var viewController: UIViewController? = self
while nil != viewController {
if viewController is EditorController {
return viewController as? EditorController
}
viewController = viewController?.parent
}
return nil
}
}
open class EditorController: ToolbarController {
/// A reference to the Editor instance.
@IBInspectable
open private(set) lazy var editor: Editor = Editor()
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open override func prepare() {
super.prepare()
display = .full
view.backgroundColor = .black
prepareStatusBar()
prepareToolbar()
prepareEditor()
}
/// Prepares the statusBar.
private func prepareStatusBar() {
statusBar.backgroundColor = .clear
}
/// Prepares the toolbar.
private func prepareToolbar() {
toolbar.backgroundColor = .clear
toolbar.depthPreset = .none
}
/// Prepares editor.
private func prepareEditor() {
editor.delegate = self
}
}
extension EditorController: EditorDelegate {}
...@@ -30,6 +30,24 @@ ...@@ -30,6 +30,24 @@
import UIKit import UIKit
extension UIViewController {
/**
A convenience property that provides access to the PhotoLibraryController.
This is the recommended method of accessing the PhotoLibraryController
through child UIViewControllers.
*/
public var photoLibraryController: PhotoLibraryController? {
var viewController: UIViewController? = self
while nil != viewController {
if viewController is PhotoLibraryController {
return viewController as? PhotoLibraryController
}
viewController = viewController?.parent
}
return nil
}
}
open class PhotoLibraryController: UIViewController { open class PhotoLibraryController: UIViewController {
/// A reference to a PhotoLibrary. /// A reference to a PhotoLibrary.
open private(set) lazy var photoLibrary: PhotoLibrary = PhotoLibrary() open private(set) lazy var photoLibrary: PhotoLibrary = PhotoLibrary()
......
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