Re: Set the bold style in an attributedstring
Re: Set the bold style in an attributedstring
- Subject: Re: Set the bold style in an attributedstring
- From: Douglas Davidson <email@hidden>
- Date: Mon, 19 Aug 2002 13:59:31 -0700
On Saturday, August 17, 2002, at 07:25 PM, malcom wrote:
How can i set the bold style (or italic/underline) in an
attributedString?
Underline is an attribute, NSUnderlineStyleAttributeName; simply add it
to the appropriate range with the value [NSNumber numberWithInt:1].
Bold and italic are traits of the font, not attributes directly on the
string. You might turn on bold, let us say, in a particular range of a
mutable attributed string with something like this (untested):
NSFontManager *fontManager = [NSFontManager sharedFontManager];
unsigned idx = range.location;
NSRange fontRange;
NSFont *font;
while (NSLocationInRange(idx, range)) {
font = [attributedString attribute:NSFontAttributeName
atIndex:idx longestEffectiveRange:&fontRange inRange:range];
fontRange = NSIntersectionRange(fontRange, range);
font = [fontManager convertFont:font
toHaveTrait:NSBoldFontMask];
[attributedString addAttribute:NSFontAttributeName value:font
range:fontRange];
idx = NSMaxRange(fontRange);
}
Wrap this in beginEditing/endEditing if your mutable attributed string
is actually an NSTextStorage.
Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.