Skip to content

Commit

Permalink
Merge pull request #23 from kazuhiro4949/feature/emoji
Browse files Browse the repository at this point in the history
fix string length for emoji
  • Loading branch information
kazuhiro4949 authored Jun 23, 2018
2 parents c941f2a + 8318d43 commit afa7d72
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
18 changes: 17 additions & 1 deletion StringStylizer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 0830;
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = "Kazuhiro Hayashi";
TargetAttributes = {
2BE7A28A20216C650039610C = {
Expand Down Expand Up @@ -504,14 +504,22 @@
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;
Expand Down Expand Up @@ -555,14 +563,22 @@
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;
Expand Down
8 changes: 4 additions & 4 deletions StringStylizer/StringStylizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ open class StringStylizer<T: StringStylizerStatus>: ExpressibleByStringLiteral {
// MARK:- Initializer

init(string: String, range: CountableRange<UInt>? = nil, attributes: [NSAttributedStringKey: Any] = [NSAttributedStringKey: Any]()) {
let range = range ?? 0..<UInt(string.characters.count)
_attrString = NSAttributedString(string: string)
let attrString = NSAttributedString(string: string)

_attrString = attrString
_attributes = attributes
_range = range
_range = range ?? 0..<UInt(attrString.length)
}

init(attributedString: NSAttributedString, range: CountableRange<UInt>, attributes: [NSAttributedStringKey: Any] = [NSAttributedStringKey: Any]()) {
Expand Down
15 changes: 14 additions & 1 deletion iOS Sample/iOS Sample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
centerLabel.attributedText = "aaa".stylize().color(.red).attr + #imageLiteral(resourceName: "Attachment").textAttachemnt(17, 17)

// build NSAttributedString.
let greed = " Hi, ".stylize().color(0x2200ee).size(12).font(.HelveticaNeue).attr

// build NSAttributedString with ranges.
let msg = "something happened ".stylize()
.range(0..<9) .color(0x009911).size(12).font(.HelveticaNeue)
.range(10..<UInt.max).color(0xaa22cc).size(14).font(.HelveticaNeue_Bold).attr

// build NSAttributedString objects and join them.
let name = "to ".stylize().color(0x23abfc).size(12).font(.HelveticaNeue).attr +
"you👩‍👩‍👦‍👦".stylize().color(0x123456).size(14).font(.HelveticaNeue_Italic).underline(.styleDouble).attr

centerLabel.attributedText = #imageLiteral(resourceName: "Attachment").textAttachemnt(17, 17) + greed + msg + name
}

override func didReceiveMemoryWarning() {
Expand Down

0 comments on commit afa7d72

Please sign in to comment.