Skip to content

Instantly share code, notes, and snippets.

@DisappearPing
Last active March 29, 2016 08:10
Show Gist options
  • Save DisappearPing/5fc7f28844b2a4d9db19 to your computer and use it in GitHub Desktop.
Save DisappearPing/5fc7f28844b2a4d9db19 to your computer and use it in GitHub Desktop.
AttributesString
//One attributed string method
let theInfoTitleString = "曼麗卡說明 Manli Card\n\n"
let theInfoTitleAttribute = [NSFontAttributeName: UIFont.systemFontOfSize(22), NSUnderlineStyleAttributeName: 1]
let theInfoDetailString = "是大魯閣草衙道專屬會員卡,更是全台首創結合購物集點、小額付款的一卡通會員卡,讓您一卡在手、暢遊草衙道!"
// let theAllInfoString = theInfoStringTitle + "\n" + theInfoStringDetail
let theInfoTitleAttributedString = NSMutableAttributedString(string: theInfoTitleString, attributes: theInfoTitleAttribute)
let theInfoDetailAttributedString = NSAttributedString(string: theInfoDetailString)
theInfoTitleAttributedString.appendAttributedString(theInfoDetailAttributedString)
//Another attributed string method
//1 set the string
let string: NSString = "曼麗卡說明 Manli Card\n\n是大魯閣草衙道專屬會員卡,更是全台首創結合購物集點、小額付款的一卡通會員卡,讓您一卡在手、暢遊草衙道!"
let attributedString = NSMutableAttributedString(string: string as String)
//2 set the attributes
let attributes = [
NSFontAttributeName: UIFont.systemFontOfSize(22),
NSForegroundColorAttributeName: UIColor.blueColor(),
NSBackgroundColorAttributeName: UIColor.yellowColor(),
NSUnderlineStyleAttributeName: 1
]
//3 form the specified string
attributedString.addAttributes(attributes, range: string.rangeOfString("曼麗卡說明 Manli Card"))
let infoLabel = UILabel(frame: CGRectMake(8,closeBtn.frame.origin.y + closeBtn.frame.size.height + 8,(infoView?.frame.size.width)! - 16,(infoView?.frame.size.height)! - closeBtn.frame.size.height - 24))
//4 add the attributed string to the attributed text
// infoLabel.attributedText = theInfoTitleAttributedString
infoLabel.attributedText = attributedString
// infoLabel.adjustsFontSizeToFitWidth = true
infoLabel.textAlignment = NSTextAlignment.Center
infoLabel.numberOfLines = 0
infoView?.addSubview(infoLabel)
// let theSignUpString = "註冊"
// let theForgotString = "忘記密碼"
//
// let attributes = [
// NSUnderlineStyleAttributeName: 1
// ]
// let theSignUpAttributedString = NSAttributedString(string: theSignUpString,attributes: attributes)
// let theForgotAttributedString = NSAttributedString(string: theForgotString,attributes: attributes)
//
// signUpBtn.setAttributedTitle(theSignUpAttributedString, forState: UIControlState.Normal)
// forgotBtn.setAttributedTitle(theForgotAttributedString, forState: UIControlState.Normal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment