September 2007
13 posts
We apologize for the untimely interruption
We have been busy bees and have had no time for hackery.
In the meantime, here are some samples to play with.
Draw yr strings cheap and easy
CGContextRef context = CGBitmapContextCreate(…);
UIPushContext(context);
UITextLabel *textLabel = [[[UITextLabel alloc] initWithFrame:CGContextGetClipBoundingBox(context)] autorelease];
[textLabel setText:@”Hello world!”];
[textLabel setCentersHorizontally:YES];
[textLabel drawContentsInRect:[textLabel bounds]];
UIPopContext(context);
You are so cover flow
@implementation SlowFlipView
// Combine something old…
- (void)flipSlowly;
{
// enable perspective transforms
LKTransform sublayerTransform = LKTransformIdentity;
sublayerTransform.m34 = 1.0 / -420.0;
[[[self superview] _layer] setSublayerTransform:sublayerTransform];
[[self _layer] setTransform:LKTransformMakeRotation(M_PI, 0, -1, 0)];
}
// with something...
My app never crashes
# ssh root@iphone cat /var/logs/CrashReporter/LatestCrash.plist | less
Take a swipe at it
In a UITable subclass:
- (int)swipe:(int)num withEvent:(GSEventRef)event;
{
if (num == kUIViewSwipeRight)
[self handleSwipeRight];
// knowing the bounds of the swipe might be useful…
CGRect rect = (GSEventGetLocationInWindow(event));
NSLog(@”origin: (%f, %f) size: (%f, %f)”, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
What goes down, must come up
- (void)buttonPressed
{
NSLog(@”Take action when a user finishes pressing a button, not when they start…”);
}
…
button = [[[UIPushButton alloc] initWithFrame:CGRectMake(…)] autorelease];
[button addTarget:self action:@selector(buttonPressed) forEvents:kUIControlEventMouseUpInside];
[button setShowPressFeedback:YES];
[button setEnabled:YES];
[view...
Just don't call it a desktop picture
UIImageView *background = [[[UIImageView alloc] initWithFrame:CGRectMake(…)] autorelease];
[background setImage:[UIImage defaultDesktopImage]];
[view addSubview:background];
Open sesame
In your UIApplication instance:
[self openURL:[NSURL URLWithString:@”http://goatse.cx”]];
How to make Gruber hate your app...
#import <GraphicsServices/GraphicsServices.h>
#import <UIKit/UIKit.h>
textLabel = [[UITextLabel alloc] initWithFrame:…];
GSFontRef font = GSFontCreateWithName(“Marker Felt”, kGSFontTraitBold, 18.0f);
[textLabel setFont:font];
CFRelease(font);
Automagicanimation
Wrap your messages to a UIView in +beginAnimations: and +endAnimations to automatically animate to the new state.
#import <UIKit/UIKit.h>
UIView *view = …
[UIView beginAnimations:nil];
[UIView setAnimationCurve:kUIAnimationCurveEaseInEaseOut];
[UIView setAnimationDuration:2.0];
// animate to the new frame in 2 seconds
[view setFrame:CGRectMake(0, 0, 100, 100)];
[UIView...
Watch your waistline
There’s no MallocDebug or other leak checking tools, so make sure you’re not becoming a pig with:
# while true; do ps -xo vsz,rsz,pagein,pmem,command | grep MyAwesomePhoneApp | grep -v grep; echo “—-“; sleep 10; done
If you don’t watch it, Springboard will shut you down at about 64 MB.
"Wow. Nice curves."
#import <UIKit/UIKit.h> - (void)drawRect:(CGRect)rect; { CGContextSetFillColorWithColor(UICurrentContext(), [UIView colorWithRed:0.5 green:0.5 blue:0.5 alpha:1.0]); [[UIBezierPath roundedRectBezierPath:rect withRoundedCorners:kUIBezierPathAllCorners withCornerRadius:10.0] fill]; }
Even from this angle, your app is still ugly
#import <UIKit/UIKit.h> #import <LayerKit/LayerKit.h> UIView *view = … LKTransform sublayerTransform = LKTransformIdentity; // adjust the distance of the sublayer transform to add perspective sublayerTransform.m34 = 1.0 / -500.0; [[[view superview] _layer] setSublayerTransform:sublayerTransform]; [(LKLayer *)[view _layer] setTransform:LKTransformMakeRotation(M_PI / 3.0, 0.5, -1,...
August 2007
2 posts
Pantone has nothing on you
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface UIView (Color)
+ (CGColorRef)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
@end
@implementation UIView (Color)
+ (CGColorRef)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
{
float rgba[4] = {red, green, blue, alpha};
CGColorSpaceRef...
Use UIHardware
Don’t assume that the size of the screen is 320x480 (who’s to say that the next version of the iPhone won’t have a 480x640 screen?) Also the status bar can be more than 20 pixels high (like during a phone call.)
Do this:
CGRect contentRect = [UIHardware fullScreenApplicationContentRect];
UINavigationBar *navigationBar = [[[UINavigationBar alloc]...