Thursday, June 23, 2011

Dynamic UILabel - Calculate height of UILabel based on Content

Following will return a new Frame size based on a given UILabel and NSString.
Thought the code below is for a UILabel, it will also work for UITextview with just a few changes.

- (CGRect) dynamicFrameForUILabels:(UILabel*) theLabel withContent:(NSString*) theContent {
    CGSize maximumLabelSize = CGSizeMake(296,9999);
    CGSize expectedLabelSize = [theContent sizeWithFont:theLabel.font
    CGRect newFrame = theLabel.frame;
    newFrame.size.height = expectedLabelSize.height;
    return newFrame;

Monday, June 20, 2011

Convert NSDictionary to JSON with SBJson

UPDATE: For the iOS5 Solution please look at

Most people writing software for Apples iOS probably had to read some sort of data from a JSON encoded string and there are heaps of examples out there who explain in every detail how you can DECODE a JSON string using the JSON-Framework (

But how about the other way around ??
Let's have a look:

1.) You need the JSON Framework from installed and added as a framework to your Project. If you don't know how to do that please read the article at

2.) You need to have your data ready as a NSDictionary or NSArray.

3.) Just use following source code and you are done :
"myDictionary" is representing your NSDictionary Object.

#import "JSON.h"
SBJsonWriter *jsonWriter = [SBJsonWriter new];
NSString *jsonString = [jsonWriter stringWithObject:myDictionary];

All Done

Monday, June 13, 2011

Java, not Python but what about Jython ?

You probably heard about Java and you might came across the problem that a customer is allowing Java applications only for several reasons. Now, if you like Python us much as I do you might want to look into Jython as it is Python only running in the Java VM AND you can access Java libraries.

There was an interesting presentation at PyCon APAC and SydPy (Python usergroup in sydney) Mark Rees which I found quite interesting.

You can find the slides here

If you don't like slides and are keen to see the whole talk just check out the video.