iPhone Vertical Text?

Discussion in 'Mac Programming' started by tfarr, May 11, 2008.

  1. tfarr macrumors newbie

    Joined:
    May 11, 2008
    #1
    Hi,

    I'm writing an iPhone application that functions (primarily) with the iPhone held landscape style (with the home button on the right).

    My application delegate sets up the window and content view (an instance of UIView) and from there my program uses Core Animation to display NSImages in different CALayers.

    I'm struggling trying to display text vertically, across the bottom of the screen. (That is, text that is displayed from left to right when the iPhone is held in the manner described above).

    Right now I'm using a UILabel to display text, but I haven't figured out how to make the text align vertically or how to change the background color (it's white at the moment).

    I haven't had any luck using the draw text approach described at the ADC:

    http://developer.apple.com/iphone/library/codinghowtos/GraphicsAndAnimation/index.html#2D-DRAW_TEXT

    With the draw text approach, I can't get anything displayed on the screen (let alone with a black or transparent background and aligned vertically).

    Any help would be greatly appreciated.

    -Toryn
     
  2. tacoman667 macrumors regular

    Joined:
    Mar 27, 2008
    #2
    Are you saying you want:

    Landscape:

    Sample


    Portrait:

    S
    a
    m
    p
    l
    e


    Am I understanding this correctly?

    Also have you tried, and I might get the code syntactically wrong here, "myView.backgroundColor = [UIColor redColor];" ?
     
  3. tfarr thread starter macrumors newbie

    Joined:
    May 11, 2008
    #3
    I'll try inserting a picture to clarify.

    [​IMG]

    With the iPhone held sideways, the text goes up and down. My goal is to have the text go from left to right with the iPhone held in that position.
     
  4. tacoman667 macrumors regular

    Joined:
    Mar 27, 2008
    #4
    I did this by accident once before I started knowing what I was doing. You would need to place the view inside a UIWindow object. The UIWindow class automatically changes the view's orientation when flipped sideways.

    At least this was my impression when I created a UILabel and UIButton on a view then clicked the blue(?) button at the top right of the UIWindow in the xib file and it changed to landscape while reorienting the view automatically. The issue I saw, and this was in Beta 4 so I haven't confirmed this in Beta 5, was that it changed the width of my view to 100% of the landscaped mode and the view zoomed in. I had to actually scroll to the bottom of the view to get to my button.
     
  5. tfarr thread starter macrumors newbie

    Joined:
    May 11, 2008
    #5
    I've tried two approaches with UILabel so far. I've tried adding the label as a subview to my UIWindow object and (in the 2nd approach) as a subview to my UIView object (which itself is a subview of a UIWindow).

    Code:
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    	
        // Set up the window and content view
        CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
        self.window = [[[UIWindow alloc] initWithFrame:screenRect] autorelease];
        CGRect contentRect = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);
        
        self.gameView = [[[GameView alloc] initWithFrame:contentRect] autorelease];
        [self.window addSubview:self.gameView];
    	
        // Create a label
        CGRect labelFrame = CGRectMake(0, 0, 50, 500);
        UILabel *aLabel = [[UILabel alloc] initWithFrame:labelFrame];
        aLabel.font = [UIFont systemFontOfSize:12];
        aLabel.textColor = [UIColor colorWithRed:0.22 green:0.54 blue:0.41 alpha:1.0];
        aLabel.textAlignment = UITextAlignmentCenter;
        self.label = aLabel;
        [aLabel release];
        [self.window addSubview: self.label];
    	
        self.label.text = @"West of House You are standing in an open field west of a";
    	
        // Show the window
        [self.window makeKeyAndVisible];
    	
    }
    
    In both cases, the text was displayed up and down... rather than left to right with the iPhone held landscape style (and when rotating the iPhone, the UILabel did not change).

    I thought the only way to control the iPhone's orientation (and have your program react to it) is to use the UIViewController class rather than the UIView class. I could be wrong though... I'm new to this game :)
     
  6. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #6
    Is there not an NSAffineTransform equivalent on the iPhone?
     
  7. tacoman667 macrumors regular

    Joined:
    Mar 27, 2008
    #7
    It looks like you are not using the IB for interface layouts, am I right? IB should automatically wire up the rotational transitions for you. That was what I was using in my last post explanation.

    I believe there is an NSAffineTransform in iPhone. I think I remember it in one of the iphonedevcentral.org tutorials. Go check those out. It should be in the Intermediate level tutorials I think.
     

Share This Page