tul*_*dev 10
你可以用NSMutableAttributedString.您可以使用不同的颜色,字体,大小等设置字符串的特定范围.
例如:
var range = NSRange(location:2,length:1) // specific location. This means "range" handle 1 character at location 2
attributedString = NSMutableAttributedString(string: originalString, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 18.0)!])
// here you change the character to red color
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: range)
label.attributedText = attributedString
Run Code Online (Sandbox Code Playgroud)
您可以更改String的许多属性.来自苹果的参考:https://developer.apple.com/library/prerelease/ios/documentation/Cocoa/Reference/Foundation/Classes/NSMutableAttributedString_Class/index.html
let text = "Sample text *"
let range = (text as NSString).rangeOfString("*")
let attributedString = NSMutableAttributedString(string:text)
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor() , range: range)
//Apply to the label
myLabel.attributedText = attributedString;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10583 次 |
| 最近记录: |