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

Contact: info@arcanelab.com

Posts Tagged: programming

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

Without much rambling, a solution for the problem presented in the title: http://code.google.com/p/qlcolorcode/

To change the color style (theme), use the following command:

defaults write org.n8gray.QLColorCode hlTheme [theme name]

Where [theme name] can be:

acid, bipolar, blacknblue, bright, contrast, darkblue, darkness, desert, easter, emacs, golden, greenlcd, ide-anjuta, ide-codewarrior, ide-devcpp, ide-eclipse, ide-kdev, ide-msvcpp, ide-xcode, kwrite, lucretia, matlab, moe, navy, nedit, neon, night, orion, pablo, peachpuff, print, rand01, seashell, slateGreen, the, typical, vampire, vim-dark, vim, whitengrey, zellner

More customization info here.

Have fun!

Text

Let me show a nice C/C++ trick I just found out:

Instead of writing:

if (function1())
function2();

you could write:

function1() && function2();

because the right side of the && operator is only evaluated (in this case: called), when function1() is true (returns a non-null value).

Subsequently, instead of:

if (!function1()) // or if (function1()==0) etc.
function2();

you could write:

function1() || function2();

Cool, eh?