View Full Version : iPhone: drawing text
rand0m3r
Apr 20, 2008, 09:27 PM
hi i read the apple docs and followed this line of code:
[myText drawAtPoint:CGPointMake(10,10) withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]];
but my string doesn't get printed. does anyone know how to draw text on a custom view for the iphone?
Sayer
Apr 20, 2008, 10:43 PM
The drawing has to be done inside of a view. Did you make a view before drawing the string?
Like maybe in a file ending in .h do...
@class MyView;
@interface iPhoneTestAppDelegate : NSObject {
UIWindow *window;
MyView *contentView;
}
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) MyView *contentView;
@end
#import "iPhoneTestAppDelegate.h"
#import "MyView.h"
@implementation iPhoneTestAppDelegate
@synthesize window;
@synthesize contentView;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Create window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Set up content view
self.contentView = [[[MyView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
[window addSubview:contentView];
// Show window
[window makeKeyAndVisible];
}
- (void)dealloc {
[contentView release];
[window release];
[super dealloc];
}
@end
Do that first.
Then in another file say MyView.h add:
#import <UIKit/UIKit.h>
@interface MyView : UIView {
}
@end
...and in MyView.m add...
#import "MyView.h"
@implementation MyView
@end
And in there add your bits to draw a string?
If not. Sign up to be an iPhone developer - its free. Download the sample code and the SDK. They are also free. Your time, well that's probably not really free, but if you spend enough you might learn something.
Duke Leto
Apr 21, 2008, 10:21 PM
You could also make a UILabel in that View class a a property. From there you can change the text and do stuff with the UILabel (setting color, size, place, the actual output, etc.).
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.