iPhone

TTStyledText problems with ampersand (’&')

by Warlock on Apr.25, 2010, under Cocoa, iPhone

I ran across an interesting problem today where I was trying to use TTStyledText from the Three20 project to create a TTStyledTextLabel that had text with links nested within it. I was trying to

Map here.

I was doing this with the following (simplified code):

[TTStyledText textFromXHTML:@"Map <a href=\"http://www.google.com/maps?f=q&hl=en\">here</a>." lineBreaks:YES URLs:YES];

As soon as I tried to put a URL in that had multiple URL parameters (and thus an &) things would disappear.

From briefly looking at the Three20 source code, I believe this because the parsing of the XHTML text is being done with an XML parser. As soon as I replaced the &s with &amp;s things started to work. This can be done using the following code:

[@"Map <a href=\"http://www.google.com/maps?f=q&hl=en\">here</a>." stringByReplacingOccurrencesOfString:@"&" withString:@"&amp;"];
Leave a Comment more...

Cocoa/UIKit BulbView

by Warlock on Jun.18, 2009, under Cocoa, iPhone

In my continuing saga to bring old-school displays to new-school (word?) devices, I’ve created a “bulb view” that displays characters in a grid of “lights”. The best way to describe it is probably just to see it:

BulbView from Mac

BulbView from Mac

BulbView on iPhone

BulbView on iPhone

Like previous LCD view you can set the colors for the lit & dim bulbs, but improved from the LCD view, you can use letters, numbers, and most punctuation/special characters. Again the rendering is done in pure Quartz2D.

The source, including demo apps for both the Mac and iPhone, can be found here. With this view I was smart and made it conditionally compile various parts so that it can be used on either the iPhone or the Mac, without needing separate files.

Leave a Comment :, , more...

Conditional Compilation for iPhone

by Warlock on Jun.17, 2009, under Cocoa, iPhone

I’m working on a view right now that I want to be able to cross compile as either an NSView for the Mac, or a UIVIew for the iPhone. I originally wrote it for Leopard, but now I’m trying to add the precompiler directives to let it cross compile between the two platforms. A quick Google search didn’t reveal anything, here are the possible definitions you can use:

#define __MAC_10_0      1000
#define __MAC_10_1      1010
#define __MAC_10_2      1020
#define __MAC_10_3      1030
#define __MAC_10_4      1040
#define __MAC_10_5      1050
#define __MAC_10_6      1060
#define __MAC_NA        9999   /* not available */

#define __IPHONE_2_0     20000
#define __IPHONE_2_1     20100
#define __IPHONE_2_2     20200
#define __IPHONE_3_0     30000
#define __IPHONE_NA      99999  /* not available */

This definition comes from Availability.h located at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/include/Availability.h (for the iPhone 3.0 SDK).

Obviously, the __MAC_10_x is actually for the version of OSX, and the __IPHONE_x_x is for iPhone.

So, if you wanted to have code conditionally compile for the iPhone (assuming 3.0 SDK) you would do something like the following:

#ifdef __IPHONE_3_0
    // iPhone
    #import <UIKit/UIKit.h>
#else
    // Mac
    #import <Cocoa/Cocoa.h>
#endif
3 Comments : more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...