Added NSAttributedString again

This commit is contained in:
Goktug Yilmaz 2016-02-25 17:04:57 -08:00
parent f8d0b5b12d
commit 0e741c1c2e
2 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,51 @@
//
// NSAttributedStringExtensions.swift
// EZSwiftExtensions
//
// Created by Lucas Farah on 18/02/16.
// Copyright (c) 2016 Lucas Farah. All rights reserved.
//
import UIKit
extension NSAttributedString {
/// EZSE: Adds bold attribute to NSAttributedString and returns it
func bold() -> NSAttributedString {
let copy = self.mutableCopy()
let range = (self.string as NSString).rangeOfString(self.string)
copy.addAttributes([NSFontAttributeName: UIFont.boldSystemFontOfSize(UIFont.systemFontSize())], range: range)
return copy as! NSAttributedString
}
/// EZSE: Adds underline attribute to NSAttributedString and returns it
func underline() -> NSAttributedString {
let copy = self.mutableCopy()
let range = (self.string as NSString).rangeOfString(self.string)
copy.addAttributes([NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue], range: range)
return copy as! NSAttributedString
}
/// EZSE: Adds italic attribute to NSAttributedString and returns it
func italic() -> NSAttributedString {
let copy = self.mutableCopy()
let range = (self.string as NSString).rangeOfString(self.string)
copy.addAttributes([NSFontAttributeName: UIFont.italicSystemFontOfSize(UIFont.systemFontSize())], range: range)
return copy as! NSAttributedString
}
/// EZSE: Adds color attribute to NSAttributedString and returns it
func color(color: UIColor) -> NSAttributedString {
let copy = self.mutableCopy()
let range = (self.string as NSString).rangeOfString(self.string)
copy.addAttributes([NSForegroundColorAttributeName: color], range: range)
return copy as! NSAttributedString
}
}
/// EZSE: Appends one NSAttributedString to another NSAttributedString and returns it
public func += (inout left: NSAttributedString, right: NSAttributedString) {
let ns = NSMutableAttributedString(attributedString: left)
ns.appendAttributedString(right)
left = ns
}

View File

@ -42,6 +42,7 @@
E1839E381BF79974002212C6 /* UIViewControllerExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1839E1C1BF79974002212C6 /* UIViewControllerExtensions.swift */; };
E1839E391BF79974002212C6 /* UIViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1839E1D1BF79974002212C6 /* UIViewExtensions.swift */; };
E197F7BD1C7FCE9D00FC6144 /* NSTimerExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E197F7BC1C7FCE9D00FC6144 /* NSTimerExtensions.swift */; };
E197F7BF1C7FD8C500FC6144 /* NSAttributedStringExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E197F7BE1C7FD8C500FC6144 /* NSAttributedStringExtensions.swift */; };
E1CB3C1C1C25FFA000DF77CD /* DoubleExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1CB3C1B1C25FFA000DF77CD /* DoubleExtensions.swift */; };
/* End PBXBuildFile section */
@ -83,6 +84,7 @@
E1839E1C1BF79974002212C6 /* UIViewControllerExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIViewControllerExtensions.swift; path = Sources/UIViewControllerExtensions.swift; sourceTree = SOURCE_ROOT; };
E1839E1D1BF79974002212C6 /* UIViewExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIViewExtensions.swift; path = Sources/UIViewExtensions.swift; sourceTree = SOURCE_ROOT; };
E197F7BC1C7FCE9D00FC6144 /* NSTimerExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSTimerExtensions.swift; sourceTree = "<group>"; };
E197F7BE1C7FD8C500FC6144 /* NSAttributedStringExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSAttributedStringExtensions.swift; sourceTree = "<group>"; };
E1CB3C1B1C25FFA000DF77CD /* DoubleExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DoubleExtensions.swift; path = Sources/DoubleExtensions.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
@ -115,6 +117,7 @@
E1CB3C1B1C25FFA000DF77CD /* DoubleExtensions.swift */,
E1839E0E1BF79974002212C6 /* EZSwiftExtensions.swift */,
E1839E0F1BF79974002212C6 /* IntExtentions.swift */,
E197F7BE1C7FD8C500FC6144 /* NSAttributedStringExtensions.swift */,
E1839E101BF79974002212C6 /* NSDateExtensions.swift */,
E1839E111BF79974002212C6 /* NSObjectExtentions.swift */,
E197F7BC1C7FCE9D00FC6144 /* NSTimerExtensions.swift */,
@ -265,6 +268,7 @@
E1839E241BF79974002212C6 /* BlockTap.swift in Sources */,
E1839E1F1BF79974002212C6 /* BlockButton.swift in Sources */,
E1839E311BF79974002212C6 /* UIColorExtensions.swift in Sources */,
E197F7BF1C7FD8C500FC6144 /* NSAttributedStringExtensions.swift in Sources */,
E1839E251BF79974002212C6 /* BlockWebView.swift in Sources */,
E1839E231BF79974002212C6 /* BlockSwipe.swift in Sources */,
E1839E221BF79974002212C6 /* BlockPinch.swift in Sources */,