Filed under: iPhone

Standard iPhone Element Sizes (Width x Height)

Core Elements:

Carrier Status bar - 320x20
UIView - 320x460
UINavigationBar - 320x44
UITabBar - 320x49
UISearchBar - 320x44
UIToolBar - 320x44

Data Input:

UIPickerView - 320x216
UIDatePicker - 320x216
UIKeyboard - 320x216

Buttons:

UISegmentedControl - 320x44
UIButton xx37

Fields:

UITextField - xx37
UISwitch 94x27
UISlider - xx23

Indicators:

UIProgressView -xx9
UIActivityIndicatorView - 37x37
UIPageControl - 38x36

UILabel Vertical / Bottom Align

I find it hard to believe that Apple when developing the iOS SDK, did not take into account that users may wish to align label text, either to the top or the bottom of a label. Instead they simply give the option of aligning it to the center, as shown below:

20090628-jkf727u2wsbsrgfhep3ja

This code allows you to align text either to the top or the bottom of a UILabel

I hope this helps someone else struggling with this issue, maybe it will be fixed in iOS 5.

Shameless Plug

(download)

I just wanted to take a second to let everyone know about Countdown, an application developed by myself which is available in the Apple App Store.

The purpose of countdown is simple, you enter a date and it shows you a countdown to that date and notifies you when the date is imminent. It supports multiple dates, local notifications and advanced user interface customisation.

What's more it is totally free and available now! Grab your copy today!!!

http://itunes.apple.com/gb/app/countdown/id343020892?mt=8

Twitter have disabled posting from Countdown

Those of you who may be wondering why you can no longer post your countdowns to Twitter should be aware that Twitter have disabled the application and banned it from their servers.

This is due to the fact that I decided to use a URL shortening service to shorten the applications links. Twitter see's this as URL obfuscation and as such is a potential security risk - quite logical when you see it from their point of view.

I have now updated the links to use the fully qualified URL, and emailed Twitter to let them know. I hope for a speedy resolution to the issue.

Sorting a NSMutableArray Randomly - Shuffle

Earlier today, I had a situation where I needed the contents of a NSMutableArrray in a random order.

There are many way in which this could be achieved, however I decided to build a Category onto NSMutableArray itself to aid in the reuse of the code, and to provide some features out of the box because the project I was actually developing was a static library for use in other project.
I am posting the code here in case anyone else finds it useful, and so I know where it is, should I ever need it again in the future.
interface:
//  NSMutableArray_Shuffling.h
//  Created by Mick Walker on 11/04/2011.
//
 
#if TARGET_OS_IPHONE
#import "UIKit/UIKit.h"
#else
#include <Cocoa/Cocoa.h>
#endif
 
 
@interface NSMutableArray (Shuffling)
- (void) shuffle;
@end

implementation:
//  NSMutableArray_Shuffling.m
//  Created by Mick Walker on 11/04/2011.
//
 
#import "NSMutableArray_Shuffling.h"
 
 
@implementation NSMutableArray (Shuffling)
 
-(void) shuffle {
    NSUInteger count = [self count];
    for(NSUInteger i = 0; i < count; i++){
        int nElements = count -1;
        int n = (arc4random() %nElements) + 1;
        [self exchangeObjectAtIndex:i withObjectAtIndex:n];
    }
}
@end

Using the code is simple, simply import the header file:
#import "NSMutableArray_Shuffling.h"

And then on an initialised NSMutableArray object call:
[someArray shuffle];
I hope that this post helps someone.