iPhone: drawing text

Discussion in 'Mac Programming' started by rand0m3r, Apr 20, 2008.

  1. rand0m3r macrumors regular

    Jun 30, 2006
    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?
  2. Sayer macrumors 6502a


    Jan 4, 2002
    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...

    @class MyView;
    @interface iPhoneTestAppDelegate : NSObject {
        UIWindow *window;
        MyView *contentView;
    @property (nonatomic, retain) UIWindow *window;
    @property (nonatomic, retain) MyView *contentView;
    #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];
    Do that first.

    Then in another file say MyView.h add:

    #import <UIKit/UIKit.h>
    @interface MyView : UIView {
    ...and in MyView.m add...

    #import "MyView.h"
    @implementation MyView
    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.
  3. Duke Leto macrumors regular

    Mar 17, 2008
    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.).

Share This Page