Basic Centering Question

Discussion in 'iOS Development' started by Steaps, Jan 29, 2009.

  1. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    I need to have my button (convertButton) in the center of the screen. How can i do so? I tried:
    Code:
    	CGRect bounds = [[UIScreen mainScreen] bounds];
    	
    	/* Create Convert Button */
    	convertButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];   
    	convertButton.frame = CGRectMake(bounds.center, 248, 86, 37);
    
    But it didn't work. Any help?

    Thanks, Stephen.4.
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
  3. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Code:
    	/* Create Convert Button */
    	convertButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];   
    	// convertButton.frame = CGRectMake(bounds.center, 248, 86, 37);
            convertButton.center = self.center;
    
    This one doesn't give errors, but doesn't appear on the screen either.

    Code:
    	/* Create Convert Button */
    	convertButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];   
    	convertButton.frame = CGRectMake(117, 248, 86, 37);
            convertButton.center = self.center;
    
    "error: incompatible type for argument 1 of 'CGRectMake'"

    Code:
    	/* Create Convert Button */
    	convertButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];   
    	convertButton.frame = CGRectMake(self.center, 248, 86, 37);
    
    "error: incompatible type for argument 1 of 'CGRectMake'"


    I tried all three, none work. I took the first one directly from your tutorial too. (Minus the ".view" as it gives an error).
  4. godogshomie

    godogshomie New Member

    Joined:
    Nov 19, 2007
    Messages:
    558
    Likes Received:
    3
    are you adding it to the subview?
  5. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Yes. 5 Character Limit

Share This Page