Commit f221f1fa by Daniel Dahan

based from PR-862, removed CharacterAttribute and cleaned up API for…

based from PR-862, removed CharacterAttribute and cleaned up API for Motion+NSMutableAttributedString
parent 69c51d10
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
9617B08C1DFCA8CF00410F8F /* SearchBar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7951CB40DC500C806FE /* SearchBar.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9617B08C1DFCA8CF00410F8F /* SearchBar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7951CB40DC500C806FE /* SearchBar.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9617B08D1DFCA8CF00410F8F /* SearchBarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7961CB40DC500C806FE /* SearchBarController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9617B08D1DFCA8CF00410F8F /* SearchBarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7961CB40DC500C806FE /* SearchBarController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9617B08E1DFCA8CF00410F8F /* TabBar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79A1CB40DC500C806FE /* TabBar.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9617B08E1DFCA8CF00410F8F /* TabBar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79A1CB40DC500C806FE /* TabBar.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9617B08F1DFCA8CF00410F8F /* CharacterAttribute.swift in Headers */ = {isa = PBXBuildFile; fileRef = 961276621DCD8B1800A7D920 /* CharacterAttribute.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9617B08F1DFCA8CF00410F8F /* Material+NSMutableAttributedString.swift in Headers */ = {isa = PBXBuildFile; fileRef = 961276621DCD8B1800A7D920 /* Material+NSMutableAttributedString.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9617B0901DFCA8CF00410F8F /* Toolbar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79F1CB40DC500C806FE /* Toolbar.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9617B0901DFCA8CF00410F8F /* Toolbar.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB79F1CB40DC500C806FE /* Toolbar.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9617B0911DFCA8CF00410F8F /* ToolbarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7A01CB40DC500C806FE /* ToolbarController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9617B0911DFCA8CF00410F8F /* ToolbarController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 96BCB7A01CB40DC500C806FE /* ToolbarController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9618006D1F4D384200CD77A1 /* Material+UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9618006C1F4D384200CD77A1 /* Material+UIViewController.swift */; }; 9618006D1F4D384200CD77A1 /* Material+UIViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9618006C1F4D384200CD77A1 /* Material+UIViewController.swift */; };
...@@ -138,7 +138,7 @@ ...@@ -138,7 +138,7 @@
965E811F1DD4D5C800D61E4B /* ErrorTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961F18E71CD93E3E008927C5 /* ErrorTextField.swift */; }; 965E811F1DD4D5C800D61E4B /* ErrorTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961F18E71CD93E3E008927C5 /* ErrorTextField.swift */; };
965E81211DD4D5C800D61E4B /* TextStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79D1CB40DC500C806FE /* TextStorage.swift */; }; 965E81211DD4D5C800D61E4B /* TextStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79D1CB40DC500C806FE /* TextStorage.swift */; };
965E81221DD4D5C800D61E4B /* TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79E1CB40DC500C806FE /* TextView.swift */; }; 965E81221DD4D5C800D61E4B /* TextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96BCB79E1CB40DC500C806FE /* TextView.swift */; };
965E81261DD4D7C800D61E4B /* CharacterAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961276621DCD8B1800A7D920 /* CharacterAttribute.swift */; }; 965E81261DD4D7C800D61E4B /* Material+NSMutableAttributedString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961276621DCD8B1800A7D920 /* Material+NSMutableAttributedString.swift */; };
966C17731F0439F600D3E83C /* Material+MotionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966C17721F0439F600D3E83C /* Material+MotionAnimation.swift */; }; 966C17731F0439F600D3E83C /* Material+MotionAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 966C17721F0439F600D3E83C /* Material+MotionAnimation.swift */; };
9685D5AF1F0F04CB00AFEB79 /* CardCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9656895E1F002F16001C656D /* CardCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9685D5AF1F0F04CB00AFEB79 /* CardCollectionViewCell.swift in Headers */ = {isa = PBXBuildFile; fileRef = 9656895E1F002F16001C656D /* CardCollectionViewCell.swift */; settings = {ATTRIBUTES = (Public, ); }; };
9685D5B01F0F04CB00AFEB79 /* CardCollectionViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 965689601F002F4C001C656D /* CardCollectionViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; }; 9685D5B01F0F04CB00AFEB79 /* CardCollectionViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = 965689601F002F4C001C656D /* CardCollectionViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
961154CB1F32A7B100A78D74 /* ChipBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChipBar.swift; sourceTree = "<group>"; }; 961154CB1F32A7B100A78D74 /* ChipBar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChipBar.swift; sourceTree = "<group>"; };
961276621DCD8B1800A7D920 /* CharacterAttribute.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharacterAttribute.swift; sourceTree = "<group>"; }; 961276621DCD8B1800A7D920 /* Material+NSMutableAttributedString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+NSMutableAttributedString.swift"; sourceTree = "<group>"; };
961527541F393C0E00E8B2AC /* LICENSE.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.md; sourceTree = "<group>"; }; 961527541F393C0E00E8B2AC /* LICENSE.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.md; sourceTree = "<group>"; };
961527551F393C0E00E8B2AC /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; }; 961527551F393C0E00E8B2AC /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
961527581F393C0E00E8B2AC /* MotionAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MotionAnimator.swift; sourceTree = "<group>"; }; 961527581F393C0E00E8B2AC /* MotionAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MotionAnimator.swift; sourceTree = "<group>"; };
...@@ -390,7 +390,6 @@ ...@@ -390,7 +390,6 @@
96090B031D9D709E00709CA6 /* Text */ = { 96090B031D9D709E00709CA6 /* Text */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
961276621DCD8B1800A7D920 /* CharacterAttribute.swift */,
96BCB79D1CB40DC500C806FE /* TextStorage.swift */, 96BCB79D1CB40DC500C806FE /* TextStorage.swift */,
96BCB79E1CB40DC500C806FE /* TextView.swift */, 96BCB79E1CB40DC500C806FE /* TextView.swift */,
96BCB79C1CB40DC500C806FE /* TextField.swift */, 96BCB79C1CB40DC500C806FE /* TextField.swift */,
...@@ -820,6 +819,7 @@ ...@@ -820,6 +819,7 @@
96BCB80A1CB410A100C806FE /* Extension */ = { 96BCB80A1CB410A100C806FE /* Extension */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
961276621DCD8B1800A7D920 /* Material+NSMutableAttributedString.swift */,
96E3C3931D397AE90086A024 /* Material+UIView.swift */, 96E3C3931D397AE90086A024 /* Material+UIView.swift */,
96F1DC871D654FDF0025F925 /* Material+CALayer.swift */, 96F1DC871D654FDF0025F925 /* Material+CALayer.swift */,
96BCB7641CB40DC500C806FE /* Material+String.swift */, 96BCB7641CB40DC500C806FE /* Material+String.swift */,
...@@ -953,7 +953,7 @@ ...@@ -953,7 +953,7 @@
9617B08C1DFCA8CF00410F8F /* SearchBar.swift in Headers */, 9617B08C1DFCA8CF00410F8F /* SearchBar.swift in Headers */,
9617B08D1DFCA8CF00410F8F /* SearchBarController.swift in Headers */, 9617B08D1DFCA8CF00410F8F /* SearchBarController.swift in Headers */,
9617B08E1DFCA8CF00410F8F /* TabBar.swift in Headers */, 9617B08E1DFCA8CF00410F8F /* TabBar.swift in Headers */,
9617B08F1DFCA8CF00410F8F /* CharacterAttribute.swift in Headers */, 9617B08F1DFCA8CF00410F8F /* Material+NSMutableAttributedString.swift in Headers */,
9617B0901DFCA8CF00410F8F /* Toolbar.swift in Headers */, 9617B0901DFCA8CF00410F8F /* Toolbar.swift in Headers */,
9617B0911DFCA8CF00410F8F /* ToolbarController.swift in Headers */, 9617B0911DFCA8CF00410F8F /* ToolbarController.swift in Headers */,
96328B9B1E05C24E009A4C90 /* CollectionViewController.swift in Headers */, 96328B9B1E05C24E009A4C90 /* CollectionViewController.swift in Headers */,
...@@ -1087,7 +1087,7 @@ ...@@ -1087,7 +1087,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
961E6BE21DDA2AF3004E6C93 /* Screen.swift in Sources */, 961E6BE21DDA2AF3004E6C93 /* Screen.swift in Sources */,
965E81261DD4D7C800D61E4B /* CharacterAttribute.swift in Sources */, 965E81261DD4D7C800D61E4B /* Material+NSMutableAttributedString.swift in Sources */,
961527861F393C0E00E8B2AC /* Motion+Array.swift in Sources */, 961527861F393C0E00E8B2AC /* Motion+Array.swift in Sources */,
965E80FF1DD4D5C800D61E4B /* BottomNavigationController.swift in Sources */, 965E80FF1DD4D5C800D61E4B /* BottomNavigationController.swift in Sources */,
965E81031DD4D5C800D61E4B /* CollectionView.swift in Sources */, 965E81031DD4D5C800D61E4B /* CollectionView.swift in Sources */,
......
/*
* Copyright (C) 2015 - 2017, 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
public enum CharacterAttribute: String {
case font = "NSFontAttributeName"
case paragraphStyle = "NSParagraphStyleAttributeName"
case forgroundColor = "NSForegroundColorAttributeName"
case backgroundColor = "NSBackgroundColorAttributeName"
case ligature = "NSLigatureAttributeName"
case kern = "NSKernAttributeName"
case strikethroughStyle = "NSStrikethroughStyleAttributeName"
case underlineStyle = "NSUnderlineStyleAttributeName"
case strokeColor = "NSStrokeColorAttributeName"
case strokeWidth = "NSStrokeWidthAttributeName"
case shadow = "NSShadowAttributeName"
case textEffect = "NSTextEffectAttributeName"
case attachment = "NSAttachmentAttributeName"
case link = "NSLinkAttributeName"
case baselineOffset = "NSBaselineOffsetAttributeName"
case underlineColor = "NSUnderlineColorAttributeName"
case strikethroughColor = "NSStrikethroughColorAttributeName"
case obliqueness = "NSObliquenessAttributeName"
case expansion = "NSExpansionAttributeName"
case writingDirection = "NSWritingDirectionAttributeName"
case verticalGlyphForm = "NSVerticalGlyphFormAttributeName"
}
public func CharacterAttributeToValue(attribute: CharacterAttribute) -> String {
switch attribute {
case .font:
return NSAttributedStringKey.font.rawValue
case .paragraphStyle:
return NSAttributedStringKey.paragraphStyle.rawValue
case .forgroundColor:
return NSAttributedStringKey.foregroundColor.rawValue
case .backgroundColor:
return NSAttributedStringKey.backgroundColor.rawValue
case .ligature:
return NSAttributedStringKey.ligature.rawValue
case .kern:
return NSAttributedStringKey.kern.rawValue
case .strikethroughStyle:
return NSAttributedStringKey.strikethroughStyle.rawValue
case .underlineStyle:
return NSAttributedStringKey.underlineStyle.rawValue
case .strokeColor:
return NSAttributedStringKey.strokeColor.rawValue
case .strokeWidth:
return NSAttributedStringKey.strokeWidth.rawValue
case .shadow:
return NSAttributedStringKey.shadow.rawValue
case .textEffect:
return NSAttributedStringKey.textEffect.rawValue
case .attachment:
return NSAttributedStringKey.attachment.rawValue
case .link:
return NSAttributedStringKey.link.rawValue
case .baselineOffset:
return NSAttributedStringKey.baselineOffset.rawValue
case .underlineColor:
return NSAttributedStringKey.underlineColor.rawValue
case .strikethroughColor:
return NSAttributedStringKey.strikethroughColor.rawValue
case .obliqueness:
return NSAttributedStringKey.obliqueness.rawValue
case .expansion:
return NSAttributedStringKey.expansion.rawValue
case .writingDirection:
return NSAttributedStringKey.writingDirection.rawValue
case .verticalGlyphForm:
return NSAttributedStringKey.verticalGlyphForm.rawValue
}
}
extension NSMutableAttributedString {
/**
Adds a character attribute to a given range.
- Parameter characterAttribute: A CharacterAttribute.
- Parameter value: Any type.
- Parameter range: A NSRange.
*/
open func add(characterAttribute: CharacterAttribute, value: Any, range: NSRange) {
addAttribute(NSAttributedStringKey(rawValue: CharacterAttributeToValue(attribute: characterAttribute)), value: value, range: range)
}
/**
Adds a Dictionary of character attributes to a given range.
- Parameter characterAttributes: A Dictionary of CharacterAttribute type keys and Any type values.
- Parameter range: A NSRange.
*/
open func add(characterAttributes: [CharacterAttribute: Any], range: NSRange) {
for (k, v) in characterAttributes {
add(characterAttribute: k, value: v, range: range)
}
}
/**
Updates a character attribute to a given range.
- Parameter characterAttribute: A CharacterAttribute.
- Parameter value: Any type.
- Parameter range: A NSRange.
*/
open func update(characterAttribute: CharacterAttribute, value: Any, range: NSRange) {
remove(characterAttribute: characterAttribute, range: range)
add(characterAttribute: characterAttribute, value: value, range: range)
}
/**
Updates a Dictionary of character attributes to a given range.
- Parameter characterAttributes: A Dictionary of CharacterAttribute type keys and Any type values.
- Parameter range: A NSRange.
*/
open func update(characterAttributes: [CharacterAttribute: Any], range: NSRange) {
for (k, v) in characterAttributes {
update(characterAttribute: k, value: v, range: range)
}
}
/**
Removes a character attribute from a given range.
- Parameter characterAttribute: A CharacterAttribute.
- Parameter range: A NSRange.
*/
open func remove(characterAttribute: CharacterAttribute, range: NSRange) {
removeAttribute(NSAttributedStringKey(rawValue: CharacterAttributeToValue(attribute: characterAttribute)), range: range)
}
/**
Removes a Dictionary of character attributes from a given range.
- Parameter characterAttributes: An Array of CharacterAttributes.
- Parameter range: A NSRange.
*/
open func remove(characterAttributes: [CharacterAttribute], range: NSRange) {
for k in characterAttributes {
remove(characterAttribute: k, range: range)
}
}
}
/*
* Copyright (C) 2015 - 2017, 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
extension NSMutableAttributedString {
/**
Adds a Dictionary of NSAttributedStringKeys for a given range.
- Parameter _ stringKeys: A Dictionary of NSAttributedStringKey type keys and Any type values.
- Parameter range: A NSRange.
*/
open func addAttributes(_ stringKeys: [NSAttributedStringKey: Any], range: NSRange) {
for (k, v) in stringKeys {
addAttribute(k, value: v, range: range)
}
}
/**
Updates a NSAttributedStringKey for a given range.
- Parameter _ stringKey: A NSAttributedStringKey.
- Parameter value: Any type.
- Parameter range: A NSRange.
*/
open func updateAttribute(_ stringKey: NSAttributedStringKey, value: Any, range: NSRange) {
removeAttribute(stringKey, range: range)
addAttribute(stringKey, value: value, range: range)
}
/**
Updates a Dictionary of NSAttributedStringKeys for a given range.
- Parameter _ stringKeys: A Dictionary of NSAttributedStringKey type keys and Any type values.
- Parameter range: A NSRange.
*/
open func updateAttributes(_ stringKeys: [NSAttributedStringKey: Any], range: NSRange) {
for (k, v) in stringKeys {
updateAttribute(k, value: v, range: range)
}
}
/**
Removes a Dictionary of NSAttributedStringKeys for a given range.
- Parameter _ stringKeys: An Array of attributedStringKeys.
- Parameter range: A NSRange.
*/
open func removeAttributes(_ stringKeys: [NSAttributedStringKey], range: NSRange) {
for k in stringKeys {
removeAttribute(k, range: range)
}
}
}
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