development of Label conversion. wip.
This commit is contained in:
parent
0e5582beed
commit
1b1c35873a
@ -22,7 +22,7 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
|||||||
// Set this to use a custom sizing object during updateView instead of the standard.
|
// Set this to use a custom sizing object during updateView instead of the standard.
|
||||||
var sizeObject: MFSizeObject?
|
var sizeObject: MFSizeObject?
|
||||||
|
|
||||||
private var scaleSize: NSNumber?
|
private var scaleSize: CGFloat?
|
||||||
|
|
||||||
// Used for scaling the font in updateView.
|
// Used for scaling the font in updateView.
|
||||||
private var originalAttributedString: NSAttributedString?
|
private var originalAttributedString: NSAttributedString?
|
||||||
@ -43,15 +43,9 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
|||||||
|
|
||||||
var hasText: Bool {
|
var hasText: Bool {
|
||||||
|
|
||||||
if let text = text, !text.isEmpty {
|
guard let text = text, let attributedText = attributedText else { return false }
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if let attributedText = attributedText, !attributedText.string.isEmpty {
|
return !text.isEmpty || !attributedText.string.isEmpty
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -60,9 +54,9 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
|||||||
|
|
||||||
func setupView() {
|
func setupView() {
|
||||||
|
|
||||||
backgroundColor = UIColor.clear
|
backgroundColor = .clear
|
||||||
numberOfLines = 0
|
numberOfLines = 0
|
||||||
lineBreakMode = NSLineBreakMode.byWordWrapping
|
lineBreakMode = .byWordWrapping
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +136,6 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
|||||||
return Label(frame: CGRect.zero)
|
return Label(frame: CGRect.zero)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Functions
|
// MARK: - Functions
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
@ -281,43 +274,40 @@ class Label: UILabel, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol {
|
|||||||
|
|
||||||
func updateView(_ size: CGFloat) {
|
func updateView(_ size: CGFloat) {
|
||||||
|
|
||||||
scaleSize = NSNumber(value: Float(size))
|
scaleSize = size
|
||||||
|
|
||||||
if let originalAttributedString = originalAttributedString {
|
if let originalAttributedString = originalAttributedString {
|
||||||
let attributedString = NSMutableAttributedString(attributedString: originalAttributedString)
|
let attributedString = NSMutableAttributedString(attributedString: originalAttributedString)
|
||||||
attributedString.removeAttribute(.font, range: NSRange(location: 0, length: attributedString.length))
|
attributedString.removeAttribute(.font, range: NSRange(location: 0, length: attributedString.length))
|
||||||
|
|
||||||
originalAttributedString.enumerateAttribute(.font, in: NSRange(location: 0, length: originalAttributedString.length), options: [], using: { value, range, stop in
|
originalAttributedString.enumerateAttribute(.font, in: NSRange(location: 0, length: originalAttributedString.length), options: [], using: { value, range, stop in
|
||||||
|
|
||||||
// Loop the original attributed string, resize the fonts.
|
// Loop the original attributed string, resize the fonts.
|
||||||
let font: UIFont? = (value as? UIFont)?.withSize((MFStyler.sizeObjectGeneric(forCurrentDevice: ((value as? UIFont)?.pointSize)!)?.getValueBased(onSize: size))!)
|
if let fontObj = value as? UIFont, let stylerSize = MFStyler.sizeObjectGeneric(forCurrentDevice: fontObj.pointSize)?.getValueBased(onSize: size) {
|
||||||
attributedString.addAttribute(.font, value: font as Any, range: range)
|
|
||||||
|
attributedString.addAttribute(.font, value: fontObj.withSize(stylerSize) as Any, range: range)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
attributedText = attributedString
|
attributedText = attributedString
|
||||||
|
|
||||||
} else if !MVMCoreGetterUtility.fequal(a: Float(standardFontSize), b: 0.0) {
|
} else if !MVMCoreGetterUtility.fequal(a: Float(standardFontSize), b: 0.0) {
|
||||||
var sizeObject: MFSizeObject? = self.sizeObject
|
if let sizeObject: MFSizeObject = self.sizeObject ?? MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize) {
|
||||||
|
self.font = self.font.withSize(sizeObject.getValueBased(onSize: size))
|
||||||
if sizeObject == nil {
|
|
||||||
sizeObject = MFStyler.sizeObjectGeneric(forCurrentDevice: standardFontSize)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.font = self.font.withSize(sizeObject?.getValueBased(onSize: size) ?? 0.0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setFont(_ font: UIFont, scale: Bool) {
|
func setFont(_ font: UIFont, scale: Bool) {
|
||||||
|
|
||||||
self.font = font
|
self.font = font
|
||||||
setScale(scale)
|
setScale(scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setScale(_ scale: Bool) {
|
func setScale(_ scale: Bool) {
|
||||||
|
|
||||||
if scale {
|
if scale {
|
||||||
standardFontSize = font.pointSize
|
standardFontSize = font.pointSize
|
||||||
if let scaleSize = scaleSize {
|
updateView(scaleSize ?? MVMCoreUISplitViewController.getApplicationViewWidth())
|
||||||
updateView(CGFloat(scaleSize.floatValue))
|
|
||||||
} else {
|
|
||||||
updateView(MVMCoreUISplitViewController.getApplicationViewWidth())
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
standardFontSize = 0
|
standardFontSize = 0
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user