Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a unicode way to make part of a string bold?

in Localizable.strings

"rulesText" = "No illegal posting! \n No weird stuff! \n There is no tolerance for objectionable content, they will be removed!";

Can I make part of this bold? Like No weird stuff! or something in this sense using unicode characters? Or some other way?

I use it like this:

textView.text = "\n\n " + NSLocalizedString("rulesText", comment: "")
like image 379
Esqarrouth Avatar asked Dec 14 '22 18:12

Esqarrouth


1 Answers

Easier way would be using NSMutableAttributedString, while using in textView.text. Here is an example:

NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]
        initWithString: NSLocalizedString("rulesText", comment: "")];

[attrString beginEditing];
[attrString addAttribute:kCTFontAttributeName 
                   value:[[UIFont boldSystemFontOfSize:12] fontName]
                   range:NSMakeRange(2, 4)]; // use range as per your character index range

[attrString endEditing];

Using this it will automatically bold characters which starts from 2nd index and then 4 characters. for example: 1234567890 - 1234567890

Hope this helps.

For SWIFT language:

let font:UIFont? = UIFont.boldSystemFontOfSize(12.0)

myMutableString.addAttribute(NSFontAttributeName, value: font!, range:  NSRange(location: 2, length: 4));

http://www.raywenderlich.com/77092/text-kit-tutorial-swift

like image 53
Mrunal Avatar answered Dec 30 '22 07:12

Mrunal