Zoltán Majoros, freelancer iOS developer living in Bonn, Germany.

Contact: info@arcanelab.com

Posts Tagged: iphone

Text

Today I noticed a very, very strange behaviour (bug?) in Xcode. I am creating buttons for my iPhone application with a custom image background and a text on top of it. The Interface Builder attributes window looks like this:

Usually I change the font-family and size for my text, but when I do this, the button dimensions suddenly grow pretty big. So I just head over to the Button Size tab and reset the dimension values to the originals, like so:

And here comes the crazyness: as I modify the width/height values, the text inside the button gets slightly blurred!

During my current development I realized that some button texts are not as sharp as others, but I had no idea why. Finally I managed to catch this “bug” by redoing the last few steps before the blur effect occured.

How to overcome this pesky issue? If I resize the button “by hand” in the view editor, the text keeps its sharpness. Odd.

Text

During the development of my latest iPhone project I faced a strange phenomenon: if I enable the title bar on a screen, the current view is placed to the coordinates (0,0), right beneath the title bar. Also, since the height of the view is not 100% (to leave space for the title bar), there’s an empty space left under the view.

Here’s an example:

For me it’s a surprise why isn’t this case handled automatically in the iPhone SDK, but with the following solution we can overcome this problem:

In the ViewController of the view add the following method:

- (void)viewWillAppear:(BOOL)animated
{
self.view.frame = [[UIScreen mainScreen] applicationFrame];
}

Before finding this solution I had to use a hack: in -(void)viewDidLoad I repositioned the view manually to its correct place. This was not only not elegant, but with the release of new iOS devices (with their different screen resolutions) this hack could have meant a potential compatibility problem.

Text

NSError *error = [[NSError alloc] init];
NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];

Text

Oh, boy. I’d been struggling with this for a while. I loaded a view from a nib, and my app kept crashing with an exception saying: loaded the “foo” nib but the view outlet was not set. I was like WTH, I definitely connected the view outlet to the ViewController, what’s going on? I kept resaving the nib, recompiling the app, but to no avail.

After digging some forum threads about this exception I got the idea of cleaning my builds. I did so, and guess what: after rebuilding my app it worked!

Sweet mother of god, why didn’t the compiler notice that I changed the nib?

Text

When you create an NSTimer, and specify it to be a non-repeat timer, you don’t have to invalidate it after it fired.

When you created a repeating timer, you send the invalidate message to it to remove it from the NSRunLoop object it was added to, and thus stopping it from being fired any more. When you invalidated an NSTimer object, you cannot use it again.

More info here and here.