Refactor PasswordSetupUI, PassportUI, GalleryUI and related modules

This commit is contained in:
Peter
2019-08-12 19:18:43 +03:00
parent aa366dee27
commit a49f04203e
311 changed files with 11406 additions and 1899 deletions

View File

@@ -0,0 +1,29 @@
import Foundation
import UIKit
public func addAttributesToStringWithRanges(_ stringWithRanges: (String, [(Int, NSRange)]), body: MarkdownAttributeSet, argumentAttributes: [Int: MarkdownAttributeSet], textAlignment: NSTextAlignment = .natural) -> NSAttributedString {
let result = NSMutableAttributedString()
var bodyAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: body.font, NSAttributedString.Key.foregroundColor: body.textColor, NSAttributedString.Key.paragraphStyle: paragraphStyleWithAlignment(textAlignment)]
if !body.additionalAttributes.isEmpty {
for (key, value) in body.additionalAttributes {
bodyAttributes[NSAttributedString.Key(rawValue: key)] = value
}
}
result.append(NSAttributedString(string: stringWithRanges.0, attributes: bodyAttributes))
for (index, range) in stringWithRanges.1 {
if let attributes = argumentAttributes[index] {
var argumentAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: attributes.font, NSAttributedString.Key.foregroundColor: attributes.textColor, NSAttributedString.Key.paragraphStyle: paragraphStyleWithAlignment(textAlignment)]
if !attributes.additionalAttributes.isEmpty {
for (key, value) in attributes.additionalAttributes {
argumentAttributes[NSAttributedString.Key(rawValue: key)] = value
}
}
result.addAttributes(argumentAttributes, range: range)
}
}
return result
}