This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'deploy/1.4.0' into productive
- Loading branch information
Showing
7 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// NSAttributedStringExtension.swift | ||
// HandyUIKit | ||
// | ||
// Created by Cihat Gündüz on 19.02.17. | ||
// Copyright © 2017 Flinesoft. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension NSAttributedString { | ||
/// 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 copy = mutableCopy() as! NSMutableAttributedString | ||
copy.addAttribute(NSFontAttributeName, value: font, range: NSMakeRange(0, length)) | ||
return copy.boundingRect(with: constraintSize, options: .usesLineFragmentOrigin, context: nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters