mh taqia
mh taqia

Reputation: 3586

Setting NSTextView selection font name

I can change the selected text font name in a text view as:

NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject: [NSFont fontWithName:"Tahoma" size:20] forKey:
    NSFontAttributeName];
[[textView textStorage] setAttributes:attributes range:[textView selectedRange]];

Above code works only if I have selection range. If my text view has no selection the code has no effect and typing font does not change. I want to change the font at cursor (if text view has no selection) and not whole of text view. (like text edit) any help would be appreciated.

Upvotes: 0

Views: 62

Answers (1)

user1720115
user1720115

Reputation:

You can change the attributes that will be applied to newly entered text with -[NSTextView setTypingAttributes:].

Upvotes: 1

Related Questions