Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rand0m3r

macrumors regular
Original poster
Jun 30, 2006
115
1
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

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
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...

Code:
@class MyView;

@interface iPhoneTestAppDelegate : NSObject {
    UIWindow *window;
    MyView *contentView;
}

@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) MyView *contentView;

@end

Code:
#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:

Code:
#import <UIKit/UIKit.h>

@interface MyView : UIView {
}

@end

...and in MyView.m add...

Code:
#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

macrumors regular
Mar 17, 2008
166
0
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.).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.