Created
May 18, 2016 11:04
-
-
Save jonathanduty/c6a54eded71fb2de4408f0b61b53aad1 to your computer and use it in GitHub Desktop.
create a 10.99 (with small "99") string that can be placed in a label.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func formatPriceString(costString:String,costLabel:UILabel) { | |
| if let range = costString.rangeOfString(".") { | |
| let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: costString) | |
| let pos = costString.startIndex.distanceTo(range.startIndex) | |
| let centsRange = NSMakeRange(pos, 3) | |
| let smallFont = UIFont(name: costLabel.font.fontName,size:10) | |
| let offsetAmount = self.costLabel.font.capHeight - smallFont!.capHeight | |
| attributeString.addAttribute(NSFontAttributeName, value: smallFont!, range: centsRange) | |
| attributeString.addAttribute(NSBaselineOffsetAttributeName, value: offsetAmount, range: centsRange) | |
| self.costLabel.attributedText = attributeString | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment