# Cocoa gems or: how this isn't about reimplementing Ruby in Objective-C

DevFeed: [Cocoa gems or: how this isn't about reimplementing Ruby in Objective-C](<https://devfeed.tech/articles/cocoa-gems-or-how-this-isn-t-about-reimplementing-ruby-in-objective-c-35512.md>)

Original publisher: [Read original article](<https://meowni.ca/posts/cocoa-gems/>)

Author: Monica Dinculescu

Published: 2014-01-30T00:00:00Z

Content type: tutorial

Language: en

Sources: [Monica Dinculescu](<https://devfeed.tech/sources/monica-dinculescu.md>)

Topics: [Objective-C](<https://devfeed.tech/topics/objective-c.md>), [Chromium](<https://devfeed.tech/topics/chromium.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [blog-post](<https://devfeed.tech/tags/blog-post.md>), [chromium](<https://devfeed.tech/tags/chromium.md>), [code](<https://devfeed.tech/tags/code.md>), [objective-c](<https://devfeed.tech/tags/objective-c.md>)

## AI overview

A developer shares practical observations from writing Objective-C with Cocoa and explains custom controls for Chromium, including an NSButton with custom padding and transparent background drawing.

## Source excerpt

Because that would be crazy. Crazy is in the next blog post. I've had to write a sizeable chunk of (fairly mediocre) Objective-C code recently, and I've formed the following opinions: It's easier if you just get over the thing with the brackets Event listeners are sooper cool Standard Cocoa controls are great if you want them to look exactly like Apple wants them to look like If you disagree with the above point, you're going to have to play subclass bingo Subclass bingo You're a subclass bingo winner when you've made a custom class out of all of the NSControls. If this sounds ridiculous, it just means you haven't tried hard enough. I started playing subclass bingo at the same time I started mumbling Cocoa, which was two months ago; I relied on the internet a lot for help. Sometimes the internet let me down, as it is wont to do, and then I had to ask actual humans things that in retrospect were fairly trivial. To save you from bringing a pox on both your houses, here are three (3) custom controls that you might one day look for. All of them live in the Chromium code zoo now. Token feeding and photography sessions are held three times a day, weather permitting. NSButton with custom padding By default, if you have an NSButton that has an image and a title, these will be squished right next to each other. This doesn't always look very pretty. By default, we get the thing on the left. We want the thing on the right. The way we're going to fix this is by creating a custom NSButtonCell, and overriding its -drawTitle method (I actually mean -drawTitle:withFrame:inView:, but I'm going to keep dropping the other parameters to make things look less scary. You can find everything in the docs, which are quite lovely). If you also want to give your button a left margin (I did. I wanted that), you can also override -drawImage and add some spacing in there. The only thing you need to keep in mind is that because you're adding all this spacing to the cell, you'll need to manually u