Re: [aString drawAtPoint:withAttributes:] Works in High Sierra, does not in Mojave - Why?

Gary L. Wade

There are a lot of things that need to be done to do drawing right, and any drawing should be done from within a view’s drawRect: method or eventually called by it. Once a view’s drawRect: method is called, everything needed to be done to set up drawing has been done. For simple text drawing, it’s often best to just use a non-editable NSTextField placed where you want it and filled with the attributes and text you want to show, and when the frameworks are ready, they will draw your text for you.
Gary L. Wade

On Nov 1, 2019, at 6:28 PM, Markus Ruggiero <mailinglists@...> wrote:

I have written a small Cocoa program that works in High Sierra but stopped working in Mojave. The program loads a graphics file from disk and displays it full screen. At the bottom it should write the filename. The picture is shown, the rect for the filename display is properly painted in dark grey, but there is no filename shown. I did upgrade my rMBP the other day from High Sierra to Mojave and since then the filename is gone. I ran the app from Xcode and verified with the debugger that the infoString is properly set. So something must be wrong with the way I draw the string. But what? Mind you I am not a Cocoa nor an Obj-C programmer. This little app is just something to play with and learn.

This method resides inside MyCustomView.m file and is supposed to draw the infoString at the bottom of the screen inside a darkGray rectangle. The rectangle is 25 pxels high an stretches across the bottom of the screen.

- (void)drawInfo: (NSString*)infoString inRect:(NSRect)infoRect {

[[NSColor darkGrayColor] set];

NSMutableDictionary *attrs = [[NSMutableDictionary alloc] init];
[attrs setObject: [NSColor whiteColor] forKey: NSForegroundColorAttributeName];
[self lockFocus];
[infoString drawAtPoint:NSMakePoint(20.0, 4.0) withAttributes:attrs];
[self unlockFocus];

Any idea?
Thanks a lot

Join { to automatically receive all group messages.