Fixed boundingRect(with:options:) miscalculation of MessageLabel like text Ꮚ˘̴͈́ꈊ˘̴͈̀Ꮚ⋆✩

This commit is contained in:
zhongwuzw
2018-08-22 17:54:48 +08:00
parent 381b4c1fd0
commit e63091c18c
2 changed files with 10 additions and 2 deletions
+5
View File
@@ -6,6 +6,11 @@ The changelog for `MessageKit`. Also see the [releases](https://github.com/Messa
## Upcoming release
### Fixed
- Fixed `boundingRect(with:options:)` miscalculation of `MessageLabel` , like text `Ꮚ˘̴͈́ꈊ˘̴͈̀Ꮚ⋆✩`、`Tomorrow is the day`.
[#824](https://github.com/MessageKit/MessageKit/pull/824) by [@zhongwuzw](https://github.com/zhongwuzw).
### Changed
- The `MessageData.emoji` case once again uses a default font of 2x the `messageLabelFont` size.
+5 -2
View File
@@ -24,6 +24,8 @@
import Foundation
private let additionalWidthForBoundingRectCalculation: CGFloat = 5.0
open class MessageSizeCalculator: CellSizeCalculator {
public init(layout: MessagesCollectionViewFlowLayout? = nil) {
@@ -216,8 +218,9 @@ open class MessageSizeCalculator: CellSizeCalculator {
internal func labelSize(for attributedText: NSAttributedString, considering maxWidth: CGFloat) -> CGSize {
let constraintBox = CGSize(width: maxWidth, height: .greatestFiniteMagnitude)
let rect = attributedText.boundingRect(with: constraintBox, options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).integral
return rect.size
// `boundingRect` method maybe not calculate correctly, like `Ꮚ˘̴͈́ꈊ˘̴͈̀Ꮚ⋆✩`, so we add 5 points to fix them temporary.
return CGSize(width: rect.width + additionalWidthForBoundingRectCalculation, height: rect.height)
}
}