Tag Archives: apple

Clean install OS X Mavericks the easy way!

I wanted to give my existing MacBook (a mid-2009) to my wife because she has had tons of battery issues, performance issues, you name it issues with the commodity Windows 7 Toshiba laptop we cursed her with a few years ago. My Macbook is older but still comes up in a fraction of the time hers does when you open the cover, lasts something like four times as long on a battery charge, and though it’s a slower processor seems to be about as fast for most of her needs.

But I didn’t want to give her a programmer’s laptop with all of my IDEs, extra browsers, compilers, databases, etc. installed on it. I wanted it to be a just like new experience. So I removed the stickers, scrubbed the aluminum exterior (though I couldn’t do much about a few small scratches on the bottom of it, the top still looks pretty new); and cleaned the screen, keyboard, and trackpad thoroughly. But when it came to completely formatting the hard drive and installing a brand new copy of OS X Mavericks it seemed like it was going to be a lot harder. For example, this article on doing a clean install was pretty typical: http://mashable.com/2013/10/23/clean-install-os-x-mavericks/

Whoof! That’s a lot of work to do something that should be pretty easy. It turns out, it can be:

  1. First make sure you can use the Command+R when you boot your MacBook to go to the recovery screen.
  2. If that worked, start up your Mac again normally and install Mavericks on it. It’s still your old stuff on the machine though, just with a new OS on top of it.
  3. Then reboot and use Command+R and go into the recovery screen.
  4. Use the Disk Utility in the recovery screen to format the hard drive and use the Reinstall OS (again a recovery screen tool). After that you’ll have a fresh clean machine with OS X Mavericks on it.

It might not be the fastest way to do it because you did two installs of Mavericks on the same machine, but it was much easier than downloading special tools and creating USB boot keys.

Easy background images for your iOS views

On an iOS game I’m developing I wanted a background image on some of my views. That’s an easy thing to do in the interface builder by simply adding a UIImageView stretched to the full extents of its containing view. However, I’ve layed it out for the four inch form factor of an iPhone 5 or the equivalent iPod Touch, how will it react to the form factor of an iPhone 4, 4S, or the older Touch?

The answer is that thanks to Auto Layout your controls can be made to adjust quite nicely, however, you’re going to have some issues with that image. By default the image view adjusted its size to the size of the containing window and squeezed my background image. Ick.

The fact that you may have two versions of the image, one Retina and one not (that is, background.png and background@2x.png) doesn’t save you because there are older devices that have both Retina displays and smaller screens. What you need is a solution that works with 4″ Retina, 3.5″ Retina, and 3.5″ non-Retina screens.

The background.png isn’t an issue. It should only come into play for non-Retina screens and to my knowledge there are no four inch non-Retina screens. Go ahead and just lay it out for 320 by 480 and be done with that one. Then, if the background is one where you can design a version that can safely lose 176 pixels in the long dimension (via a border or other area that can be safely clipped), then lay out a background that is 640 by 1136 with 88 pixels at the top and bottom that will be clipped off when it is viewed on the smaller screen. Then you can change one small setting on the image view so it will center and clip the image rather than squeeze it and you’re done.

The background image as it would appear on an iPhone 5 (640 x 1136).

The background image as it would appear on an iPhone 5 or similar 4″ Retina device (640 x 1136).

The same image automatically cropped top and bottom as seen on an iPhone 4 (or similar Retina device with a 3.5" screen).

The same image automatically cropped top and bottom as seen on an iPhone 4 (or similar Retina device with a 3.5″ screen).

The mode setting that makes it work. By default it's set to "Scale to Fill", change it to "Aspect Fill" and it will keep the width full but center and crop the image.

The mode setting that makes it work. By default it’s set to “Scale to Fill”, change it to “Aspect Fill” and it will keep the width full but center and crop the image.

Two images + One setting = Something that gives you easy backgrounds for all small iOS devices

But, if that’s not cutting it for you, there’s another choice. Have a third image ready. iOS has naming conventions for images (you saw some of them above with the @2x) that helps them load the right image for Retina or non-Retina and iPhone/iPod Touch vs iPad. However, they didn’t include a naming convention for the different form factors of 3.5″ vs. 4″.

So an alternative is to load a different image specifically for the Retina 3.5″ and let the non-Retina 3.5″ and Retina 4″ be handled automatically by the image naming conventions. Here’s some sample code that could go in the viewDidLoad to override and load an alternate image:

- (void)viewDidLoad {
  [super viewDidLoad];

  // Do any additional setup after loading the view, typically from a nib.

  // We're relying on automatic loading of background.png and
  // background@2x.png to handle the non-Retina 3.5" devices and the Retina 4"
  // devices.
  // So we're manually detecting Retina 3.5" devices and loading a special
  // image just for those.
  if  ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) &&
    [[UIScreen mainScreen] scale] > 1.0 &&
    [UIScreen mainScreen].bounds.size.height != 568.f) {
      [self.backgroundImageView setImage:[UIImage imageNamed:@"alternateBackground.png"]];