Dwayne Harris
6 years ago
9 changed files with 141 additions and 89 deletions
-
8elpha-ios.xcodeproj/project.pbxproj
-
13elpha-ios/AccountTableViewController.swift
-
1elpha-ios/AlertView.xib
-
10elpha-ios/Base.lproj/Main.storyboard
-
4elpha-ios/StatusTableViewController.swift
-
106elpha-ios/StatusView.swift
-
25elpha-ios/StatusView.xib
-
40elpha-ios/String+HtmlAttributed.swift
-
23elpha-ios/UIColor+HexString.swift
@ -0,0 +1,40 @@ |
|||||
|
// |
||||
|
// String+HtmlAttributed.swift |
||||
|
// elpha-ios |
||||
|
// |
||||
|
// Created by Dwayne Harris on 11/6/18. |
||||
|
// Copyright © 2018 Elpha. All rights reserved. |
||||
|
// |
||||
|
|
||||
|
import UIKit |
||||
|
|
||||
|
extension String { |
||||
|
func htmlAttributed(size: CGFloat, centered: Bool = false) -> NSAttributedString? { |
||||
|
do { |
||||
|
let htmlString = """ |
||||
|
<style> |
||||
|
html * { |
||||
|
font-family: -apple-system !important; |
||||
|
font-size: \(size)px !important; |
||||
|
color: \(UIColor(named: "Text")!.hexString()) !important; |
||||
|
text-align: \(centered ? "center" : "initial") !important; |
||||
|
} |
||||
|
</style> |
||||
|
\(self) |
||||
|
""" |
||||
|
|
||||
|
guard let data = htmlString.data(using: String.Encoding.utf16) else { |
||||
|
return nil |
||||
|
} |
||||
|
|
||||
|
return try NSAttributedString( |
||||
|
data: data, |
||||
|
options: [.documentType: NSAttributedString.DocumentType.html], |
||||
|
documentAttributes: nil |
||||
|
) |
||||
|
} catch { |
||||
|
print("\(error)") |
||||
|
return nil |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
// |
||||
|
// UIColor+HexString.swift |
||||
|
// elpha-ios |
||||
|
// |
||||
|
// Created by Dwayne Harris on 11/6/18. |
||||
|
// Copyright © 2018 Elpha. All rights reserved. |
||||
|
// |
||||
|
|
||||
|
import UIKit |
||||
|
|
||||
|
extension UIColor { |
||||
|
func hexString() -> String { |
||||
|
var r: CGFloat = 0 |
||||
|
var g: CGFloat = 0 |
||||
|
var b: CGFloat = 0 |
||||
|
var a: CGFloat = 0 |
||||
|
|
||||
|
getRed(&r, green: &g, blue: &b, alpha: &a) |
||||
|
|
||||
|
let rgb: Int = (Int)(r * 255) << 16 | (Int)(g * 255) << 8 | (Int)(b * 255) << 0 |
||||
|
return String(format: "#%06x", rgb) |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue