Reputation: 117
is it possible to get the font name and its size of a specific character in string in Swift?
I want to make a textview in which you can type with different fonts. I did this, but the problem is for example if something, lets say "hello" is written in Helvetica 16pt, and my current font Helvetica 24 pt, and then I want to write something more in "hello", let say "helloworld". This is possible in swift using attributed strings, but the word "hello" will be 16pt, and the word "world", will be 24pt. So, how to detect the font of the "hello" word, and then change the font automatically, and continue typing with the same font?
Upvotes: 0
Views: 224
Reputation: 5188
You should have a look at the NSAttributedString documentation. The font size attribute you mentioned is actually contained within the NSFontAttributeName
key, which stores an NSFont
which has both font type and size. You can directly access that using fontAttributesInRange:
if you know where you want to look in the string.
Upvotes: 1