Skip to content

Commit

Permalink
Merge pull request #8 from tbaranes/feature/swift3
Browse files Browse the repository at this point in the history
Swift 3 support
  • Loading branch information
Tom Baranes authored Sep 11, 2016
2 parents 2032c4f + 3c54645 commit 7b30370
Show file tree
Hide file tree
Showing 16 changed files with 427 additions and 153 deletions.
19 changes: 4 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode7.3
osx_image: xcode8
notifications:
email: false
env:
Expand All @@ -8,17 +8,11 @@ env:
- LANG=en_US.UTF-8
- WORKSPACE=FittableFontLabel.xcworkspace
- IOS_FRAMEWORK_SCHEME="FittableFontLabel iOS"
- IOS_SDK=iphonesimulator9.3
- IOS_SDK=iphonesimulator10.0
- EXAMPLE_SCHEME="iOS Example"
matrix:
- DESTINATION="OS=8.1,name=iPhone 4S" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="YES"
- DESTINATION="OS=8.2,name=iPhone 5" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
- DESTINATION="OS=8.3,name=iPhone 5S" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
- DESTINATION="OS=8.4,name=iPhone 6" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
- DESTINATION="OS=9.0,name=iPhone 6" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
- DESTINATION="OS=9.1,name=iPhone 6 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
- DESTINATION="OS=9.2,name=iPhone 6S" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
- DESTINATION="OS=9.3,name=iPhone 6S Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO"
- DESTINATION="OS=10.0,name=iPhone 6S" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES"
- DESTINATION="OS=10.0,name=iPhone 5" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="YES"
script:
- set -o pipefail
- xcodebuild -version
Expand All @@ -42,8 +36,3 @@ script:
- if [ $BUILD_EXAMPLE == "YES" ]; then
xcodebuild -workspace "$WORKSPACE" -scheme "$EXAMPLE_SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty -c;
fi

# Run `pod lib lint` if specified
- if [ $POD_LINT == "YES" ]; then
pod lib lint;
fi
8 changes: 2 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ All notable changes to the project will be documented in this file.

#### API breaking changes

N/A

#### Enhancements

N/A
- Swift 3 compatibility

#### Bugfixes

N/A
- Improved issue with long strings in small labels getting truncated

## [1.3.0](https://github.com/tbaranes/FittableFontLabel/releases/tag/1.3.0) (15/08/2016)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,14 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = Recisio;
TargetAttributes = {
E2C3AF3D1C4FBFB300EB275B = {
CreatedOnToolsVersion = 7.2;
DevelopmentTeam = TNVENL2JX3;
LastSwiftMigration = 0800;
ProvisioningStyle = Automatic;
};
};
};
Expand Down Expand Up @@ -333,24 +336,29 @@
E2C3AF4E1C4FBFB300EB275B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = TNVENL2JX3;
INFOPLIST_FILE = "$(SRCROOT)/iOS Example/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.recisio.IncrementableLabel;
PRODUCT_NAME = "FittableFontLabel iOS";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
E2C3AF4F1C4FBFB300EB275B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = TNVENL2JX3;
INFOPLIST_FILE = "$(SRCROOT)/iOS Example/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.recisio.IncrementableLabel;
PRODUCT_NAME = "FittableFontLabel iOS";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
26 changes: 1 addition & 25 deletions FittableFontLabel Example/iOS Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
return true
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

24 changes: 12 additions & 12 deletions FittableFontLabel Example/iOS Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@ class ViewController: UIViewController {

@IBOutlet weak var autoFittableLabel: FittableFontLabel! {
didSet {
setupLabel(autoFittableLabel)
setup(label: autoFittableLabel)
}
}

@IBOutlet weak var labelFittableWidthAndHeight: UILabel! {
didSet {
labelFittableWidthAndHeight.text = words[0]
setupLabel(labelFittableWidthAndHeight)
setup(label: labelFittableWidthAndHeight)
}
}

@IBOutlet weak var labelFittableWidth: UILabel! {
didSet {
setupLabel(labelFittableWidth)
labelFittableWidth.text = words[0..<3].joinWithSeparator(" ")
setup(label: labelFittableWidth)
labelFittableWidth.text = words[0..<3].joined(separator: " ")
}
}

@IBOutlet weak var attributedLabelFittable: UILabel! {
didSet {
setupLabel(attributedLabelFittable)
setup(label: attributedLabelFittable)
attributedLabelFittable.text = words[0]
}
}

@IBOutlet weak var autoFittableLabelWithInsets: FittableFontLabel! {
didSet {
setupLabel(autoFittableLabelWithInsets)
setup(label: autoFittableLabelWithInsets)
}
}

Expand All @@ -54,16 +54,16 @@ class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
let timer = NSTimer.scheduledTimerWithTimeInterval(0.7, target: self, selector: #selector(reloadLabels), userInfo: nil, repeats: true);
NSRunLoop.mainRunLoop().addTimer(timer, forMode: NSRunLoopCommonModes)
let timer = Timer.scheduledTimer(timeInterval: 0.7, target: self, selector: #selector(reloadLabels), userInfo: nil, repeats: true);
RunLoop.main.add(timer, forMode: RunLoopMode.commonModes)


self.view.backgroundColor = UIColor(white: 0.1, alpha: 1.0)
}

private func setupLabel(label: UILabel) {
private func setup(label: UILabel) {
label.layer.borderWidth = 2.0
label.layer.borderColor = UIColor.redColor().CGColor
label.layer.borderColor = UIColor.red.cgColor
label.layer.cornerRadius = 3.0
}

Expand All @@ -78,14 +78,14 @@ class ViewController: UIViewController {

let paragraph = NSMutableParagraphStyle()
paragraph.lineSpacing = 10.0
paragraph.alignment = .Center
paragraph.alignment = .center
let attributes = [NSParagraphStyleAttributeName: paragraph]
let attributedText = NSAttributedString(string: labelFittableWidthAndHeight.text!, attributes: attributes)
attributedLabelFittable.attributedText = attributedText
attributedLabelFittable.fontSizeToFit(maxFontSize: 50)

let screenWidth = labelFittableWidth.window!.screen.bounds.width
let newWidth = CGFloat(arc4random()) % (screenWidth - 50.0)
let newWidth = CGFloat(arc4random_uniform(UInt32(screenWidth - 50.0)))
labelFittableWidth.frame.size.width = newWidth
labelFittableWidth.fontSizeToFit(maxFontSize: 50)
}
Expand Down
2 changes: 1 addition & 1 deletion FittableFontLabel.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ s.source = { :git => "https://github.com/tbaranes/FittableFontLabel.g

s.ios.deployment_target = '8.0'
s.requires_arc = true
s.source_files = 'Sources/*.swift'
s.source_files = 'Source/*.swift'

end
3 changes: 3 additions & 0 deletions FittableFontLabel/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
line_length: 180
included:
- ../Source
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,49 @@ import XCTest
@testable import FittableFontLabel

class FittableFontLabelTests: XCTestCase {

override func setUp() {
super.setUp()
}

override func tearDown() {
super.tearDown()
}

// MARK: Helper

let shortText = "Etiam turpis elit"
// swiftlint:disable:next line_length
let longText = "Etiam turpis elit, efficitur nec suscipit vitae, aliquam vitae lorem. Aenean mauris tortor, semper vel facilisis nec, facilisis ut neque. Aliquam erat volutpat. Nam eget varius mauris, ut condimentum quam. Duis ex nisi, iaculis in ex ut, lobortis pretium est. Sed non lorem venenatis, fermentum quam aliquet, ultrices arcu. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Duis ullamcorper convallis tellus, vitae bibendum mi dapibus in. Morbi pellentesque aliquet urna, id aliquet orci efficitur sed. Donec et mi urna. Proin sagittis semper massa in semper."
}

// MARK: - Single line

extension FittableFontLabelTests {

// MARK: Expecting size
// MARK: Expecting size

func testSingleLine_expectingMinSize() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
label.text = longText
let fontSize = label.fontSizeThatFits(text: longText, maxFontSize: 20, minFontScale: 0.1, rectSize: CGSize(width: 20, height: 20))
XCTAssertEqual(fontSize, 20 * 0.1)
let fontSize = label.fontSizeThatFits(text: longText, maxFontSize: 20, minFontScale: 0.1,
rectSize: CGSize(width: 20, height: 20))
XCTAssertEqual(fontSize, 2.0)
}

func testSingleLine_expectingMaxSize() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
label.text = longText
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1, rectSize: CGSize(width: 1000, height: 1000))
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1,
rectSize: CGSize(width: 1000, height: 1000))
XCTAssertEqual(fontSize, 20)
}

func testSingleLine_expectingMediumSize() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
label.text = longText
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 100, minFontScale: 0.1, rectSize: CGSize(width: 100, height: 100))
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 100, minFontScale: 0.1,
rectSize: CGSize(width: 100, height: 100))
XCTAssertTrue(fontSize > 100 * 0.1)
XCTAssertTrue(fontSize < 100)
}
Expand All @@ -57,14 +61,16 @@ extension FittableFontLabelTests {

func testSingleLine_withEmptyTextLabel() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1, rectSize: CGSize(width: 1000, height: 1000))
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1,
rectSize: CGSize(width: 1000, height: 1000))
XCTAssertEqual(fontSize, 20)
}

func testSingleLine_withSizeZero() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1, rectSize: CGSize(width: 0, height: 0))
XCTAssertEqual(fontSize, 20 * 0.1)
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1,
rectSize: CGSize(width: 0, height: 0))
XCTAssertEqual(fontSize, 2.0)
}

}
Expand All @@ -79,23 +85,26 @@ extension FittableFontLabelTests {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
label.numberOfLines = 0
label.text = longText
let fontSize = label.fontSizeThatFits(text: longText, maxFontSize: 20, minFontScale: 0.1, rectSize: CGSize(width: 0, height: 0))
XCTAssertEqual(fontSize, 20 * 0.1)
let fontSize = label.fontSizeThatFits(text: longText, maxFontSize: 20, minFontScale: 0.1,
rectSize: CGSize(width: 0, height: 0))
XCTAssertEqual(fontSize, 2.0)
}

func testMultiline_expectingMaxSize() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
label.numberOfLines = 0
label.text = longText
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1, rectSize: CGSize(width: 1000, height: 1000))
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1,
rectSize: CGSize(width: 1000, height: 1000))
XCTAssertEqual(fontSize, 20)
}

func testMultiline_expectingMediumSize() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
label.numberOfLines = 0
label.text = longText
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 100, minFontScale: 0.1, rectSize: CGSize(width: 100, height: 100))
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 100, minFontScale: 0.1,
rectSize: CGSize(width: 100, height: 100))
XCTAssertTrue(fontSize > 100 * 0.1)
XCTAssertTrue(fontSize < 100)
}
Expand All @@ -105,15 +114,17 @@ extension FittableFontLabelTests {
func testMultiline_withEmptyTextLabel() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
label.numberOfLines = 0
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1, rectSize: CGSize(width: 1000, height: 1000))
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1,
rectSize: CGSize(width: 1000, height: 1000))
XCTAssertEqual(fontSize, 20)
}

func testMultiline_withSizeZero() {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
label.numberOfLines = 0
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1, rectSize: CGSize(width: 0, height: 0))
XCTAssertEqual(fontSize, 20 * 0.1)
let fontSize = label.fontSizeThatFits(text: shortText, maxFontSize: 20, minFontScale: 0.1,
rectSize: CGSize(width: 0, height: 0))
XCTAssertEqual(fontSize, 2.0)
}

}
}
Loading

0 comments on commit 7b30370

Please sign in to comment.