Search code examples
cocoafontsnstextviewbold

How do i make selection bold in the NStextview?


Use the setFont: range: ? but what i want to do here is only to make the selection bold as the selection may have different font attribute,so,anyone can tell that?


Solution

  • Like this:

    NSMutableAttributedString* text = [textView textStorage];
    [text applyFontTraits:NSBoldFontMask range:NSMakeRange(0,[text length])];
    

    where the range is the range of text you want to make bold.