Skip to content

Commit

Permalink
Xcode 10.2 and Swift 5 support
Browse files Browse the repository at this point in the history
- Fix AttributedLabel crash (fix #76)
- Move special HTML symbols table to plist file in order to avoid compilation problems (fix #75)
  • Loading branch information
Pavel Sharanda committed Mar 27, 2019
1 parent d517896 commit b9dccdc
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 2,147 deletions.
4 changes: 2 additions & 2 deletions Atributika.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Atributika"
s.version = "4.6.9"
s.version = "4.7.0"
s.summary = "Convert text with HTML tags, hashtags, mentions, links into NSAttributedString. Make them clickable with UILabel drop-in replacement."
s.description = <<-DESC
`Atributika` is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or even standard ios data detectors and style them with various attributes like font, color, etc. `Atributika` comes with drop-in label replacement `AttributedLabel` which is able to make any detection clickable.
Expand All @@ -9,7 +9,7 @@ Pod::Spec.new do |s|
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Pavel Sharanda" => "[email protected]" }
s.social_media_url = "https://twitter.com/e2f"
s.ios.deployment_target = "8.0"
s.ios.deployment_target = "9.0"
s.osx.deployment_target = "10.10"
s.watchos.deployment_target = "2.0"
s.tvos.deployment_target = "9.0"
Expand Down
45 changes: 30 additions & 15 deletions Atributika.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
1BB55AE41E5C73F000CE6EAD /* Style.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BB55AD01E5C73EF00CE6EAD /* Style.swift */; };
1BDDF5691E683A8F006374F6 /* Snippet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BDDF5681E683A8F006374F6 /* Snippet.swift */; };
1BDDF56B1E6841EA006374F6 /* AttributedLabelDemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1BDDF56A1E6841EA006374F6 /* AttributedLabelDemoViewController.swift */; };
1BE17B56224C14C200E1943A /* html_specials.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1BE17B55224C14C200E1943A /* html_specials.plist */; };
1BE17B57224C14C200E1943A /* html_specials.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1BE17B55224C14C200E1943A /* html_specials.plist */; };
1BE17B58224C14C200E1943A /* html_specials.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1BE17B55224C14C200E1943A /* html_specials.plist */; };
1BE17B59224C14C200E1943A /* html_specials.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1BE17B55224C14C200E1943A /* html_specials.plist */; };
52D6D9871BEFF229002C0205 /* Atributika.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* Atributika.framework */; };
52D6D99B1BEFF375002C0205 /* AtributikaTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52D6D9971BEFF375002C0205 /* AtributikaTests.swift */; };
DD7502861C68FDDC006590AF /* AtributikaTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52D6D9971BEFF375002C0205 /* AtributikaTests.swift */; };
Expand Down Expand Up @@ -109,6 +113,7 @@
1BB55AD01E5C73EF00CE6EAD /* Style.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Style.swift; path = Sources/Style.swift; sourceTree = "<group>"; };
1BDDF5681E683A8F006374F6 /* Snippet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Snippet.swift; sourceTree = "<group>"; };
1BDDF56A1E6841EA006374F6 /* AttributedLabelDemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AttributedLabelDemoViewController.swift; sourceTree = "<group>"; };
1BE17B55224C14C200E1943A /* html_specials.plist */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; name = html_specials.plist; path = Sources/html_specials.plist; sourceTree = "<group>"; };
52D6D97C1BEFF229002C0205 /* Atributika.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Atributika.framework; sourceTree = BUILT_PRODUCTS_DIR; };
52D6D9861BEFF229002C0205 /* Atributika-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Atributika-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
52D6D9971BEFF375002C0205 /* AtributikaTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AtributikaTests.swift; path = Tests/AtributikaTests/AtributikaTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -210,6 +215,7 @@
52D6D9721BEFF229002C0205 = {
isa = PBXGroup;
children = (
1BE17B55224C14C200E1943A /* html_specials.plist */,
1B38369F1F97C224001DB333 /* AttributedLabel.swift */,
1BB55AD01E5C73EF00CE6EAD /* Style.swift */,
1BB55ACC1E5C73EF00CE6EAD /* AttributedText.swift */,
Expand Down Expand Up @@ -455,42 +461,43 @@
TargetAttributes = {
1B2F838C1E5C98A4009AFBCA = {
CreatedOnToolsVersion = 8.2.1;
LastSwiftMigration = 1000;
DevelopmentTeam = 6UG65RB759;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
52D6D97B1BEFF229002C0205 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
52D6D9851BEFF229002C0205 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0900;
LastSwiftMigration = 1020;
};
52D6D9E11BEFFF6E002C0205 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
52D6D9EF1BEFFFBE002C0205 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
52D6DA0E1BF000BD002C0205 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
DD7502791C68FCFC006590AF = {
CreatedOnToolsVersion = 7.2.1;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
DD75028C1C690C7A006590AF = {
CreatedOnToolsVersion = 7.2.1;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
};
};
};
buildConfigurationList = 52D6D9761BEFF229002C0205 /* Build configuration list for PBXProject "Atributika" */;
compatibilityVersion = "Xcode 6.3";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Expand Down Expand Up @@ -527,6 +534,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1BE17B56224C14C200E1943A /* html_specials.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -541,20 +549,23 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1BE17B58224C14C200E1943A /* html_specials.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
52D6D9EE1BEFFFBE002C0205 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1BE17B59224C14C200E1943A /* html_specials.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
52D6DA0D1BF000BD002C0205 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1BE17B57224C14C200E1943A /* html_specials.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -708,11 +719,11 @@
CLANG_ANALYZER_NONNULL = YES;
CLANG_ENABLE_CODE_COVERAGE = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 6UG65RB759;
INFOPLIST_FILE = Demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.psharanda.Demo;
PRODUCT_BUNDLE_IDENTIFIER = org.psharanda.Atributika.Demo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_VERSION = 4.0;
Expand All @@ -727,11 +738,11 @@
CLANG_ANALYZER_NONNULL = YES;
CLANG_ENABLE_CODE_COVERAGE = NO;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 6UG65RB759;
INFOPLIST_FILE = Demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.psharanda.Demo;
PRODUCT_BUNDLE_IDENTIFIER = org.psharanda.Atributika.Demo;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
Expand Down Expand Up @@ -862,7 +873,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Configs/Atributika.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.Atributika.Atributika-iOS";
Expand All @@ -886,7 +897,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Configs/Atributika.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Atributika.Atributika-iOS";
PRODUCT_NAME = Atributika;
Expand All @@ -903,6 +914,7 @@
CLANG_ENABLE_CODE_COVERAGE = NO;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = Configs/AtributikaTests.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Atributika.Atributika-iOS-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -918,6 +930,7 @@
CLANG_ENABLE_CODE_COVERAGE = NO;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = Configs/AtributikaTests.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Atributika.Atributika-iOS-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -1119,6 +1132,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_CODE_COVERAGE = NO;
INFOPLIST_FILE = Configs/AtributikaTests.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Atributika.Atributika-tvOS-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1134,6 +1148,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_CODE_COVERAGE = NO;
INFOPLIST_FILE = Configs/AtributikaTests.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Atributika.Atributika-tvOS-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
11 changes: 7 additions & 4 deletions Sources/AttributedLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ open class AttributedLabel: UIView {
addSubview(label)

label.translatesAutoresizingMaskIntoConstraints = false
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[label]|", options: [], metrics: nil, views: ["label": label]))
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[label]|", options: [], metrics: nil, views: ["label": label]))

label.topAnchor.constraint(equalTo: topAnchor).isActive = true
label.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
label.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
label.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
}

//MARK: - overrides
Expand Down Expand Up @@ -131,11 +134,11 @@ open class AttributedLabel: UIView {
let usedRect = layoutManager.usedRect(for: textContainer)
let dy = max(0, (bounds.height - usedRect.height)/2)
highlightableDetections.forEach { detection in
let nsrange = NSRange(detection.range, in: inheritedString.string)
let nsrange = NSRange(detection.range, in: text.string)
layoutManager.enumerateEnclosingRects(forGlyphRange: nsrange, withinSelectedGlyphRange: NSRange(location: NSNotFound, length: 0), in: textContainer, using: { (rect, stop) in
var finalRect = rect
finalRect.origin.y += dy
self.addDetectionAreaButton(frame: finalRect, detection: detection, text: String(inheritedString.string[detection.range]))
self.addDetectionAreaButton(frame: finalRect, detection: detection, text: String(text.string[detection.range]))
})
}
}
Expand Down
Loading

0 comments on commit b9dccdc

Please sign in to comment.