1

My project demands that I use a custom Font, but this font have strange images in some characters like ( ) , . / etc...

The design agency said to replace the font in these characters to a more common font like Gill Sans.

So in a NSString = @"(My Favorite's. Love this!)";

I need to have the main custom font for the text and the Gill Sans font for the ( ' . ! and )

Is there a code where I can just pass the string and it returns some NSString with NSAttributedString with the font changes?

Thanks,

Jitendra
  • 5,055
  • 2
  • 22
  • 42
gmogames
  • 2,993
  • 1
  • 28
  • 40

2 Answers2

1

use NSAttributedString to set multible font and size for string in ios NSAttributedString Class Reference,example

NANNAV
  • 4,875
  • 4
  • 32
  • 50
1

here is a sample code:

NSString *displayText = @"(My Favorite's. Love this!)";

NSMutableAttributedString *attributedString = [NSMutableAttributedString attributedStringWithString:displayText];

[attributedString setFont:[UIFont systemFontOfSize:15] range:[displayText rangeOfString:@"."]];

The last line will change the font of the point (.) to system font of size 15. You can search another characters in the string using the same function, and replace another properties of the string with setter methods of the form setX:range: of the NSAttributedString class. Hope it helps!

lucaslt89
  • 2,431
  • 1
  • 20
  • 30