Thor Frølich

Former game developer.
Now making sweet love to Xcode.

At STRANGE LOOP, to be precise.

 

    12 Aug 2011

    A client recently wanted a UIPickerView similar to the one Mobile Safari uses when selecting a dropdown menu on a webpage. It shows a checkmark when the user taps an entry and doesn't select entries when they scroll past the middle region, which is the default behavior of a vanilla UIPickerView.

    This turned out to be a bit of work, so I thought I'd package up a generalized version of it and release it on Github.

    { ios ,  UIPickerView ,  checkmark }
    10 Aug 2011

    I've just run into an annoying bug regarding custom embedded fonts in an iOS app. It turns out that if you're embedding multiple fonts from the same family, the compiled app will for some of the fonts use one of its siblings instead.

    This answer on the invaluable Stack Overflow tells you to change the family name in each of font files to get around this issue. Here's one way of doing that:

    1. Download and install TTX/FontTools.
    2. Use the newly installed "ttx" command line tool to create a .ttx file from each of your fonts files.
    3. Open these .ttx files in a text editor and use search and replace to rename all instance of only the family name. I replaced them with the name of the particular font I was modifying (eg. "MyFont" became "MyFontBold").
    4. Use "ttx" again to convert the edited .ttx files into .otf files, ready to be added to your Xcode project.
    { ios ,  fonts }
    28 Jul 2011

    For a client project I recently had to add a subview to a UITableViewCell's contentView and have it centered both horizontally and vertically. This cannot be achieved by simply setting something like the following when configuring the cell in cellForRowAtIndexPath:

     myAwesomeSubView.center = cell.contentView.center;
        
    

    The above will only center the subview horizontally. To achieve vertical centering however, you can instead subclass UITableViewCell and override its method for laying out subviews:

     - (void)layoutSubviews
        {
            [super layoutSubviews];
        
            for (UIView *view in self.contentView.subviews)
            {
                view.center = self.contentView.center;
            }
        }
    

    I've had to do this a couple of times and keep forgetting how, so I thought I'd commit it to Google for posterity and anyone else who might need to do the same.

    { iOS ,  code ,  UITableViewCell }