Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public extension NSMutableAttributedString {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

self.applyAttribute(NSForegroundColorAttributeName, withValue: value, forRange: attributeRange)
self.applyAttribute(NSAttributedString.Key.foregroundColor, withValue: value, forRange: attributeRange)

return self
}
Expand All @@ -54,7 +54,7 @@ public extension NSMutableAttributedString {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

self.applyAttribute(NSFontAttributeName, withValue: value, forRange: attributeRange)
self.applyAttribute(NSAttributedString.Key.font, withValue: value, forRange: attributeRange)

return self
}
Expand All @@ -77,7 +77,7 @@ public extension NSMutableAttributedString {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

self.applyAttribute(NSBackgroundColorAttributeName, withValue: value, forRange: attributeRange)
self.applyAttribute(NSAttributedString.Key.backgroundColor, withValue: value, forRange: attributeRange)

return self
}
Expand All @@ -100,7 +100,7 @@ public extension NSMutableAttributedString {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

self.applyAttribute(NSKernAttributeName, withValue: value as AnyObject, forRange: attributeRange)
self.applyAttribute(NSAttributedString.Key.kern, withValue: value as AnyObject, forRange: attributeRange)

return self
}
Expand All @@ -123,7 +123,7 @@ public extension NSMutableAttributedString {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

self.applyAttribute(NSUnderlineStyleAttributeName, withValue: value as AnyObject, forRange: attributeRange)
self.applyAttribute(NSAttributedString.Key.underlineStyle, withValue: value as AnyObject, forRange: attributeRange)

return self
}
Expand All @@ -146,7 +146,7 @@ public extension NSMutableAttributedString {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

self.applyAttribute(NSUnderlineColorAttributeName, withValue: value, forRange: attributeRange)
self.applyAttribute(NSAttributedString.Key.underlineColor, withValue: value, forRange: attributeRange)

return self
}
Expand All @@ -169,7 +169,7 @@ public extension NSMutableAttributedString {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

self.applyAttribute(NSStrikethroughStyleAttributeName, withValue: value as AnyObject, forRange: attributeRange)
self.applyAttribute(NSAttributedString.Key.strikethroughStyle, withValue: value as AnyObject, forRange: attributeRange)

return self
}
Expand All @@ -192,7 +192,7 @@ public extension NSMutableAttributedString {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

self.applyAttribute(NSStrikethroughColorAttributeName, withValue: value, forRange: attributeRange)
self.applyAttribute(NSAttributedString.Key.strikethroughColor, withValue: value, forRange: attributeRange)

return self
}
Expand All @@ -215,11 +215,76 @@ public extension NSMutableAttributedString {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

self.applyAttribute(NSLinkAttributeName, withValue: value as AnyObject, forRange: attributeRange)
self.applyAttribute(NSAttributedString.Key.link, withValue: value as AnyObject, forRange: attributeRange)

return self
}

/**
This function adds paragraphy style with line spacing to attributed string.

- warning: If text passed in "text" parameter is not found, attribute will be applied to whole attributed string. Only first occurence of "text" is styled.

- parameter value - CGFloat which should be applied as linespacing to the paragraph style
- parameter text - String for which the paragraph style will be applied to (optional, default = whole attributed string)

- returns: Modified NSMutableAttributedString
*/
func lineSpacing(_ value:CGFloat, forText text:String? = nil) -> NSMutableAttributedString {

var attributeRange:NSRange? = nil
if let textForAttribute = text {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = value

self.applyAttribute(NSAttributedString.Key.paragraphStyle, withValue: paragraphStyle as AnyObject, forRange: attributeRange)

return self
}

/**
This function adds paragraphy style to attributed string.
*/

func paragraphStyle(_ paragraphStyle:NSParagraphStyle, forText text:String? = nil) -> NSMutableAttributedString {
var attributeRange:NSRange? = nil
if let textForAttribute = text {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

self.applyAttribute(NSAttributedString.Key.paragraphStyle, withValue: paragraphStyle as AnyObject, forRange: attributeRange)

return self
}

/**
This function adds paragraph style with text alignment attributed string.

- warning: If text passed in "text" parameter is not found, attribute will be applied to whole attributed string. Only first occurence of "text" is styled.

- parameter alignment - NSTextAlignment which should be applied as alignment to the paragraph style
- parameter text - String for which the paragraph style will be applied to (optional, default = whole attributed string)

- returns: Modified NSMutableAttributedString
*/
func alignment(_ alignment:NSTextAlignment, forText text:String? = nil) -> NSMutableAttributedString {

var attributeRange:NSRange? = nil
if let textForAttribute = text {
attributeRange = self.getRangeOfStringInSelf(textForAttribute)
}

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center

self.applyAttribute(NSAttributedString.Key.paragraphStyle, withValue: paragraphStyle as AnyObject, forRange: attributeRange)

return self
}

// MARK: Clear attributes

/**
Expand Down Expand Up @@ -249,7 +314,7 @@ public extension NSMutableAttributedString {

// MARK: Applying attributes

fileprivate func applyAttribute(_ attributeName:String, withValue value:AnyObject, forRange range:NSRange? = nil) {
fileprivate func applyAttribute(_ attributeName: NSAttributedString.Key, withValue value: AnyObject, forRange range: NSRange? = nil) {

let attributeRange = range ?? self.getRangeOfSelf()
self.addAttribute(attributeName, value: value, range: attributeRange)
Expand Down
31 changes: 27 additions & 4 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = Example;
TargetAttributes = {
E0C323FD1D2463D000712168 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0800;
LastSwiftMigration = 1000;
ProvisioningStyle = Manual;
};
};
Expand Down Expand Up @@ -260,13 +260,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -306,13 +316,23 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -331,6 +351,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -340,29 +361,31 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 1B5DE12EDCA817CEB23756C0 /* Pods-Example.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Example/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.example.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
E0C324121D2463D000712168 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = FA3411A5A628154C440137FA /* Pods-Example.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Example/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.example.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
30 changes: 30 additions & 0 deletions Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down Expand Up @@ -59,6 +79,16 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
Loading