Porting my app Biblicious from iOS to OS X, Part 2

With WWDC 2014 coming up, this post probably won’t get read very much, but here it goes…

The first game view hurdle was fixed. In my last post I mentioned that one doesn’t get as many event notifications when a view on OS X is about to display as compared to iOS. My main problem here was that the four NSButtons would not slide off of the screen when the view first became active. They would slide off just fine when one clicked an answer. I determined that the issue was one of timing, between the view being created and me telling the buttons to move when they hadn’t actually been created since the view wasn’t displaying. I was right. This little snippet of code at the end of initWithNibName did the job:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, .0625 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{

            [self moveOut:kBUTTON_ALL shouldHide:YES];



After the view is created, all I do is wait approximately 600th of a second and then tell the buttons to move out & to start the game.


The second hurdle wasted hours of my time. I increased the font size for all of the controls on the main game view to 36pt. Everything looked good, even the sample text on the four buttons. When I ran the game, the text of the buttons were tiny again, while the rest of the controls were at 36pt font size. I tried everything I could think of, searched StackOverflow, iPhoneDevSDK, and Apple’s own developer forums to no avail. I removed the default dummy text from Interface Builder, I removed the background image of the button, changed the type of button, set the font in code (multiple ways!) using NSAttributedString, tried with setFont, accessed the NSButtonCell property directly and used setFont. I even tried telling the OS to redraw the button by calling the button’s needsDisplay method. I couldn’t change the font size nor the color. I went to the “main menu” of Biblicious and put some code in so if I pressed a button, its text color would change. It worked. I put code in to change the text color of a button if a different button was pressed. It worked, too. I ripped all of that test code out and went to Interface Builder again. I was going to check the font settings in the NSButtonCell instead of just the NSButton. I selected the cell and as I was clicking on the different property inspectors, I saw something weird: BibliciousButtonCell : NSButtonCell. What?!?! When I first started this port back in (apparently) August of 2013, I subclassed the NSButtonCell to properly manage the word-wrapping. All of my hard work was being overwritten by the code in my subclass. In particular, the line that reset the font changes I was making:

NSFont *sysFont = [NSFont systemFontOfSize:16];

To fix the problem, I changed the 16 to 36 in order to match the rest of the game interface. As you can see, the subclass still needs a little work, but at least the text is larger now. I had to get this post out while the frustration was still fresh. Learn from my mistakes. 🙂

First screen with large text

First screen with large text