Commit adae879d authored by Evan W. Patton's avatar Evan W. Patton Committed by Evan W. Patton

Fix font size and encoding issues with iOS Label

Change-Id: I65f4d034903e93dd19f09e051a4192b7ae628da8
parent 35f6a800
...@@ -14,10 +14,9 @@ public final class Label: ViewComponent, AbstractMethodsForViewComponent, Access ...@@ -14,10 +14,9 @@ public final class Label: ViewComponent, AbstractMethodsForViewComponent, Access
fileprivate var _hasMargins = false fileprivate var _hasMargins = false
fileprivate var _htmlContent: String = "" fileprivate var _htmlContent: String = ""
fileprivate var _htmlFormat = false fileprivate var _htmlFormat = false
fileprivate var _fontSize: Float64 = 0 fileprivate var _fontSize = kFontSizeDefault
fileprivate var _isBigText = false fileprivate var _isBigText = false
fileprivate var _textColor = Int32(bitPattern: Color.default.rawValue) fileprivate var _textColor = Int32(bitPattern: Color.default.rawValue)
fileprivate var _userFontSize = kFontSizeDefault
public var HighContrast: Bool = false public var HighContrast: Bool = false
public override init(_ parent: ComponentContainer) { public override init(_ parent: ComponentContainer) {
...@@ -33,7 +32,7 @@ public final class Label: ViewComponent, AbstractMethodsForViewComponent, Access ...@@ -33,7 +32,7 @@ public final class Label: ViewComponent, AbstractMethodsForViewComponent, Access
parent.add(self) parent.add(self)
Height = kLengthPreferred Height = kLengthPreferred
Width = kLengthPreferred Width = kLengthPreferred
FontSize = Float64(kFontSizeDefault) FontSize = kFontSizeDefault
} }
func updateFontSize() { func updateFontSize() {
...@@ -41,13 +40,13 @@ public final class Label: ViewComponent, AbstractMethodsForViewComponent, Access ...@@ -41,13 +40,13 @@ public final class Label: ViewComponent, AbstractMethodsForViewComponent, Access
updateFormattedContent() updateFormattedContent()
} else { } else {
if form?.BigDefaultText == true { if form?.BigDefaultText == true {
if _userFontSize == kFontSizeDefault { if _fontSize == kFontSizeDefault {
_view.font = _view.font.withSize(CGFloat(kFontSizeLargeDefault)) _view.font = _view.font.withSize(CGFloat(kFontSizeLargeDefault))
} else { } else {
_view.font = _view.font.withSize(CGFloat(_userFontSize)) _view.font = _view.font.withSize(CGFloat(_fontSize))
} }
} else { } else {
_view.font = _view.font.withSize(CGFloat(_userFontSize)) _view.font = _view.font.withSize(CGFloat(_fontSize))
} }
} }
_view.sizeToFit() _view.sizeToFit()
...@@ -139,12 +138,12 @@ public final class Label: ViewComponent, AbstractMethodsForViewComponent, Access ...@@ -139,12 +138,12 @@ public final class Label: ViewComponent, AbstractMethodsForViewComponent, Access
} }
} }
@objc public var FontSize: Float64 { @objc public var FontSize: Float {
get { get {
return _fontSize return Float(_view.font.pointSize)
} }
set(size) { set(size) {
_userFontSize = Float(size) _fontSize = size
updateFontSize() updateFontSize()
} }
} }
...@@ -236,7 +235,9 @@ public final class Label: ViewComponent, AbstractMethodsForViewComponent, Access ...@@ -236,7 +235,9 @@ public final class Label: ViewComponent, AbstractMethodsForViewComponent, Access
let data = ("<div style=\"\(style)\">" + _htmlContent + "</div>").data(using: .utf8) ?? Data() let data = ("<div style=\"\(style)\">" + _htmlContent + "</div>").data(using: .utf8) ?? Data()
var options = [NSAttributedString.DocumentReadingOptionKey:Any]() var options = [NSAttributedString.DocumentReadingOptionKey:Any]()
options[NSAttributedString.DocumentReadingOptionKey.documentType] = options[NSAttributedString.DocumentReadingOptionKey.documentType] =
NSAttributedString.DocumentType.html NSAttributedString.DocumentType.html
options[NSAttributedString.DocumentReadingOptionKey.characterEncoding] =
NSUTF8StringEncoding
_view.attributedText = try? NSAttributedString(data: data, _view.attributedText = try? NSAttributedString(data: data,
options: options, options: options,
documentAttributes: nil) documentAttributes: nil)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment