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
//Usage | |
lbl.attributedText = htmlToAttributedString ("html text") | |
//Assign attributed string | |
func htmlToAttributedString(string : String) -> NSAttributedString{ | |
var attribStr = NSMutableAttributedString() | |
do {//, allowLossyConversion: true | |
attribStr = try NSMutableAttributedString(data: string.dataUsingEncoding(NSUnicodeStringEncoding)!, options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) | |
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
//Here whenever isChecked value is assigned, it will update the text as per true or false condition | |
class CheckBox: UIButton { | |
var mySelectedAttributedTitle = NSAttributedString(string:" TRUE", attributes: [NSFontAttributeName: UIFont.ioniconOfSize(26), NSForegroundColorAttributeName : UIColor.blackColor()]) | |
// Bool property | |
var isCheck: Bool = false { | |
didSet{ | |
if isCheck == true { | |
//Assign true case image/text to the button like as follows |
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
extension String { | |
func convertToBool() -> Bool? { | |
switch self { | |
case "true", "1", "yes": | |
return true | |
case "false", "0", "no": | |
return false | |
default: | |
return nil | |
} |