A swift component that shows levels of whatever you want.
- Swift 4.2
You have a fully functional demo in PGLevelIndicator folder
Just drag and drop Source folder in your project
use_frameworks!
pod 'PGLevelIndicator'
- Create attributed strings with the text you want
let font: UIFont? = UIFont(name: "Avenir-Book", size: 18)
let fontSuper: UIFont? = UIFont(name: "Avenir-Book", size: 10)
let attStringNO2 = NSMutableAttributedString(string: "NO2", attributes: [.font: font!])
attStringNO2.setAttributes([.font: fontSuper!, .baselineOffset: -5],
range: NSRange(location: 2, length: 1))
- Create an array of parameters:
let parameters = [ItemParameters(title: attStringNO2, titleColor: UIColor.red, level: .low),
ItemParameters(title: attStringO3, titleColor: UIColor.yellow, level: .medium),
ItemParameters(title: attStringpM10, titleColor: UIColor.green, level: .high),
ItemParameters(title: attStringPM25, titleColor: UIColor.orange, level: .low)]
(The level parameter is not used, but maybe in future revisions we will use it)
- Create the PGLevelIndicator object:
let levelIndicator = PGLevelIndicator(frame: CGRect(x: 0,
y: 100,
width: self.view.frame.size.width,
height: self.view.frame.size.width),
itemsParameters: parameters)
- And finally, add the levelIndicator to the main view
self.view.addSubview(levelIndicator!)
And voilá....
If you have any questions, please don't hesitate to create an issue.
PGLevelIndicator is available under the MIT license. See the LICENSE file for more info.
If you use it, I'll be happy to know about it.