Skip to content

Commit

Permalink
Support for Xcode 10 and Swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Baranes committed Sep 18, 2018
1 parent 32d2036 commit 8aaadbf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
E2C3AF3D1C4FBFB300EB275B = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = TNVENL2JX3;
LastSwiftMigration = 0900;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -361,7 +361,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.recisio.IncrementableLabel;
PRODUCT_NAME = "FittableFontLabel iOS";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -376,7 +376,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.recisio.IncrementableLabel;
PRODUCT_NAME = "FittableFontLabel iOS";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
4 changes: 2 additions & 2 deletions FittableFontLabel Example/iOS Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let timer = Timer.scheduledTimer(timeInterval: 0.7, target: self, selector: #selector(reloadLabels), userInfo: nil, repeats: true);
RunLoop.main.add(timer, forMode: RunLoopMode.commonModes)
RunLoop.main.add(timer, forMode: RunLoop.Mode.common)


self.view.backgroundColor = UIColor(white: 0.1, alpha: 1.0)
Expand All @@ -80,7 +80,7 @@ class ViewController: UIViewController {
let paragraph = NSMutableParagraphStyle()
paragraph.lineSpacing = 10.0
paragraph.alignment = .center
let attributes = [NSAttributedStringKey.paragraphStyle: paragraph]
let attributes = [NSAttributedString.Key.paragraphStyle: paragraph]
let attributedText = NSAttributedString(string: labelFittableWidthAndHeight.text!, attributes: attributes)
attributedLabelFittable.attributedText = attributedText
attributedLabelFittable.fontSizeToFit(maxFontSize: 50)
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>
11 changes: 4 additions & 7 deletions FittableFontLabel/FittableFontLabel.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
TargetAttributes = {
E2227AA11CCE80C5006C4289 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0900;
LastSwiftMigration = 1000;
};
E2227AAB1CCE80C5006C4289 = {
CreatedOnToolsVersion = 7.3;
Expand Down Expand Up @@ -378,8 +378,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.tbaranes.FittableFontLabel;
PRODUCT_NAME = FittableFontLabel;
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -399,8 +398,7 @@
PRODUCT_NAME = FittableFontLabel;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down Expand Up @@ -499,8 +497,7 @@
PRODUCT_NAME = FittableFontLabel;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = ReleaseTest;
};
Expand Down
2 changes: 1 addition & 1 deletion Source/FittableFontLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ open class FittableFontLabel: UILabel {

open override func drawText(in rect: CGRect) {
let insets = UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
super.drawText(in: UIEdgeInsetsInsetRect(rect, insets))
super.drawText(in: rect.inset(by: insets))
}

}
Expand Down
6 changes: 3 additions & 3 deletions Source/UILabelExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public extension UILabel {

extension UILabel {

private func currentAttributedStringAttributes() -> [NSAttributedStringKey: Any] {
var newAttributes = [NSAttributedStringKey: Any]()
private func currentAttributedStringAttributes() -> [NSAttributedString.Key: Any] {
var newAttributes = [NSAttributedString.Key: Any]()
attributedText?.enumerateAttributes(in: NSRange(0..<(text?.count ?? 0)), options: .longestEffectiveRangeNotRequired, using: { attributes, _, _ in
newAttributes = attributes
})
Expand All @@ -90,7 +90,7 @@ extension UILabel {
private func binarySearch(string: String, minSize: CGFloat, maxSize: CGFloat, size: CGSize, constraintSize: CGSize) -> CGFloat {
let fontSize = (minSize + maxSize) / 2
var attributes = currentAttributedStringAttributes()
attributes[NSAttributedStringKey.font] = font.withSize(fontSize)
attributes[NSAttributedString.Key.font] = font.withSize(fontSize)

let rect = string.boundingRect(with: constraintSize, options: .usesLineFragmentOrigin, attributes: attributes, context: nil)
let state = numberOfLines == 1 ? singleLineSizeState(rect: rect, size: size) : multiLineSizeState(rect: rect, size: size)
Expand Down

0 comments on commit 8aaadbf

Please sign in to comment.