Edit AllPages

Is there still no easy way to create a menu item that adds strikethrough to text in a textView?

I see the option in the font panel, but I see no easy way to replicate it into a menu item in the Fonts menu of my app.



This page describes making an NSAttributedString with specific font styles - including strikethrough and underline:

Here’s an excerpt taken from it:

*The underline attribute has only two values defined, NSNoUnderlineStyle and NSSingleUnderlineStyle, but these can be combined with NSUnderlineByWorkMask and NSUnderlineStrikethroughMask to extend their behavior. By bitwise-ORing these values in different combinations, you can specify no underline, a single underline, a single strikethrough, both an underline and a strikethrough, and whether the line is drawn for whitespace or not.

You can edit an NSView through the view’s NSTextStorage object which is a subclass of NSMutableAttributedString.

Is this what you were looking for?

– RyanBates

There’s also a new attribute, NSStrikethroughStyleAttributeName, introduced in Panther that controls the same effect. Anyhoo, here’s a quick category on NSTextView that implements a strikethrough action method that works like the corresponding -bold: and -underline: methods. There’s 2 methods that are functionally identical (more or less), one using the Panther attribute and one using the Jaguar attribute mask. – Bo

@implementation NSTextView (StrikeThrough) // note: I tried to make these methods behave identically to how the // -bold: and -underline: action methods, even when they act kinda stupid.

Exactly what I was looking for, Bo, thanks a ton! –GarrettMurray