Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Merge branch 'deploy/1.3.0' into productive
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Feb 19, 2017
2 parents a6dd505 + 8114f29 commit 03e5642
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 7 deletions.
2 changes: 1 addition & 1 deletion HandyUIKit.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "HandyUIKit"
s.version = "1.2.1"
s.version = "1.3.0"
s.summary = "Handy UI features that should have been part of UIKit in the first place."

s.description = <<-DESC
Expand Down
14 changes: 13 additions & 1 deletion HandyUIKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
A11830F31E5996FD00CBE087 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A11830F21E5996FD00CBE087 /* StringExtension.swift */; };
A11830F41E5996FD00CBE087 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A11830F21E5996FD00CBE087 /* StringExtension.swift */; };
A11830F61E599BF600CBE087 /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A11830F51E599BF600CBE087 /* StringExtensionTests.swift */; };
A11830F71E599BF600CBE087 /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A11830F51E599BF600CBE087 /* StringExtensionTests.swift */; };
A14E0AC61E1F986A00DFC788 /* HandyUIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A14E0ABC1E1F986A00DFC788 /* HandyUIKit.framework */; };
A14E0AE41E1F987C00DFC788 /* HandyUIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A14E0ADB1E1F987C00DFC788 /* HandyUIKit.framework */; };
A14E0B111E1F9B3100DFC788 /* UIViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A14E0B0E1E1F9B3100DFC788 /* UIViewExtension.swift */; };
Expand Down Expand Up @@ -41,6 +45,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
A11830F21E5996FD00CBE087 /* StringExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
A11830F51E599BF600CBE087 /* StringExtensionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensionTests.swift; sourceTree = "<group>"; };
A14E0ABC1E1F986A00DFC788 /* HandyUIKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HandyUIKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A14E0AC51E1F986A00DFC788 /* HandyUIKit-iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "HandyUIKit-iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
A14E0ADB1E1F987C00DFC788 /* HandyUIKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HandyUIKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -155,6 +161,7 @@
children = (
A1F2216D1E3E0B7700419B06 /* CoreExtensionTests.swift */,
A1F2217B1E3E2C5500419B06 /* CoreGraphicsExtensionTests.swift */,
A11830F51E599BF600CBE087 /* StringExtensionTests.swift */,
);
path = Code;
sourceTree = "<group>";
Expand All @@ -174,6 +181,7 @@
A14E0B0E1E1F9B3100DFC788 /* UIViewExtension.swift */,
A1F221671E3E07DD00419B06 /* UIColorExtension.swift */,
A1F2216A1E3E08AE00419B06 /* CoreGraphicsExtension.swift */,
A11830F21E5996FD00CBE087 /* StringExtension.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -389,7 +397,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint > /dev/null; then\n swiftlint\nelse\n echo \"SwiftLint not installed, download it from https://github.com/realm/SwiftLint\"\nfi";
shellScript = "if [ \"${CONFIGURATION}\" = \"Debug\" ]; then\n if which swiftlint > /dev/null; then\n swiftlint\n else\n echo \"SwiftLint not installed, download it from https://github.com/realm/SwiftLint\"\n fi\nfi";
};
A1F2218C1E3FEF2800419B06 /* Run Swift Linter */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -414,6 +422,7 @@
files = (
A1F221801E3E778F00419B06 /* ColorSpaces.swift in Sources */,
A1F221681E3E07DD00419B06 /* UIColorExtension.swift in Sources */,
A11830F31E5996FD00CBE087 /* StringExtension.swift in Sources */,
A1F2216B1E3E08AF00419B06 /* CoreGraphicsExtension.swift in Sources */,
A14E0B111E1F9B3100DFC788 /* UIViewExtension.swift in Sources */,
);
Expand All @@ -425,6 +434,7 @@
files = (
A1F2217C1E3E2C5500419B06 /* CoreGraphicsExtensionTests.swift in Sources */,
A1F221701E3E0B8400419B06 /* CoreExtensionTests.swift in Sources */,
A11830F61E599BF600CBE087 /* StringExtensionTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -434,6 +444,7 @@
files = (
A1F221811E3E778F00419B06 /* ColorSpaces.swift in Sources */,
A1F221691E3E07DD00419B06 /* UIColorExtension.swift in Sources */,
A11830F41E5996FD00CBE087 /* StringExtension.swift in Sources */,
A1F2216C1E3E08AF00419B06 /* CoreGraphicsExtension.swift in Sources */,
A14E0B121E1F9B3100DFC788 /* UIViewExtension.swift in Sources */,
);
Expand All @@ -445,6 +456,7 @@
files = (
A1F2217D1E3E2C5500419B06 /* CoreGraphicsExtensionTests.swift in Sources */,
A1F221711E3E0B8500419B06 /* CoreExtensionTests.swift in Sources */,
A11830F71E599BF600CBE087 /* StringExtensionTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ alt="Build Status">
alt="codebeat badge">
</a>
<a href="https://github.com/Flinesoft/HandyUIKit/releases">
<img src="https://img.shields.io/badge/Version-1.2.1-blue.svg"
alt="Version: 1.2.1">
<img src="https://img.shields.io/badge/Version-1.3.0-blue.svg"
alt="Version: 1.3.0">
</a>
<img src="https://img.shields.io/badge/Swift-3.0-FFAC45.svg"
alt="Swift: 3.0">
Expand Down Expand Up @@ -53,7 +53,7 @@ You can of course also just include this framework manually into your project by
Place the following line to your Cartfile:

``` Swift
github "Flinesoft/HandyUIKit"
github "Flinesoft/HandyUIKit" ~> 1.3
```

Now run `carthage update`. Then drag & drop the HandyUIKit.framework in the Carthage/build folder to your project. Now you can `import HandyUIKit` in each class you want to use its features. Refer to the [Carthage README](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) for detailed / updated instructions.
Expand All @@ -68,7 +68,7 @@ platform :ios, '8.0'
use_frameworks!

target 'MyAppTarget' do
pod 'HandyUIKit', '~> 1.1'
pod 'HandyUIKit', '~> 1.3'
end
```

Expand Down Expand Up @@ -230,6 +230,27 @@ let originZeroRect1 = CGRect(size: someSize)
let originZeroRect2 = CGRect(width: 100, height: 50)
```


### StringExtension
#### .width(for fixedHeight:font:)
Calculates and returns the height needed to fit the text into a width-constrained rect.

``` Swift
let loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

loremIpsum.height(forFixedWidth: 300, font: UIFont.systemFont(ofSize: 14, weight: UIFontWeightBold))
// => 183.77734375
```

#### .height(for fixedWidth:font:)
Calculates and returns the width needed to fit the text into a height-constrained rect.

``` Swift
loremIpsum.width(forFixedHeight: 21, font: UIFont.systemFont(ofSize: 12, weight: UIFontWeightUltraLight))
// => 2351.0390625
```


## Contributing

Contributions are welcome. Please just open an Issue on GitHub to discuss a point or request a feature or send a Pull Request with your suggestion. If there's a related discussion on the Swift Evolution mailing list, please also post the thread name with a link.
Expand Down
38 changes: 38 additions & 0 deletions Sources/Code/Extensions/StringExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// StringExtension.swift
// HandyUIKit
//
// Created by Cihat Gündüz on 19.02.17.
// Copyright © 2017 Flinesoft. All rights reserved.
//

import UIKit

extension String {
/// Calculates and returns the height needed to fit the text into a width-constrained rect.
///
/// - Parameters:
/// - fixedWidth: The fixed width of the rect.
/// - font: The font of the text to calculate for.
/// - Returns: The height needed to fit the text into a width-constrained rect.
public func height(forFixedWidth fixedWidth: CGFloat, font: UIFont) -> CGFloat {
let constraintSize = CGSize(width: fixedWidth, height: .greatestFiniteMagnitude)
return rect(for: constraintSize, font: font).height
}

/// Calculates and returns the width needed to fit the text into a height-constrained rect.
///
/// - Parameters:
/// - fixedHeight: The fixed height of the rect.
/// - font: The font of the text to calculate for.
/// - Returns: The width needed to fit the text into a height-constrained rect.
public func width(forFixedHeight fixedHeight: CGFloat, font: UIFont) -> CGFloat {
let constraintSize = CGSize(width: .greatestFiniteMagnitude, height: fixedHeight)
return rect(for: constraintSize, font: font).width
}

private func rect(for constraintSize: CGSize, font: UIFont) -> CGRect {
let attributes = [NSFontAttributeName: font]
return (self as NSString).boundingRect(with: constraintSize, options: .usesLineFragmentOrigin, attributes: attributes, context: nil)
}
}
2 changes: 1 addition & 1 deletion Sources/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.2.1</string>
<string>1.3.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
29 changes: 29 additions & 0 deletions Tests/Code/StringExtensionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// StringExtensionTests.swift
// HandyUIKit
//
// Created by Cihat Gündüz on 19.02.17.
// Copyright © 2017 Flinesoft. All rights reserved.
//

import XCTest

@testable import HandyUIKit

class StringExtensionTests: XCTestCase {
let loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." // swiftlint:disable:this line_length

func testHeight() {
let font = UIFont(name: "Helvetica Neue", size: 16)!
let calculatedHeight = loremIpsum.height(forFixedWidth: 300, font: font)

XCTAssertEqualWithAccuracy(calculatedHeight, 205.04, accuracy: 0.001)
}

func testWidth() {
let font = UIFont(name: "Helvetica Neue", size: 16)!
let calculatedHeight = loremIpsum.width(forFixedHeight: 21, font: font)

XCTAssertEqualWithAccuracy(calculatedHeight, 3014.592, accuracy: 0.001)
}
}
14 changes: 14 additions & 0 deletions UsageExamples.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,17 @@ let someSize = CGSize(width: 100, height: 50)

let originZeroRect1 = CGRect(size: someSize)
let originZeroRect2 = CGRect(width: 100, height: 50)


//: ## StringExtension
//: ### .width(for fixedHeight:font:)
//: Calculates and returns the height needed to fit the text into a width-constrained rect.

let loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

loremIpsum.height(forFixedWidth: 300, font: UIFont.systemFont(ofSize: 14, weight: UIFontWeightBold))

//: ### .height(for fixedWidth:font:)
//: Calculates and returns the width needed to fit the text into a height-constrained rect.

loremIpsum.width(forFixedHeight: 21, font: UIFont.systemFont(ofSize: 12, weight: UIFontWeightUltraLight))

0 comments on commit 03e5642

Please sign in to comment.