Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 23, 2008, 08:47 PM   #1
seventoes
macrumors newbie
 
Join Date: Feb 2008
Adding a UIButton to a view programatically

Probably a noob question here, I'm still getting started with all of these cool new toys , but this doesnt seem to be working:

Code:
startButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[startButton setTitle:@"Start Game" forState:UIControlStateNormal];
startButton.bounds = CGRectMake(120, 200, 80, 20);
		
[self addSubview:startButton];
Am i missing something simple?
seventoes is offline   0 Reply With Quote
Old Jul 23, 2008, 09:27 PM   #2
firewood
macrumors 603
 
Join Date: Jul 2003
Location: Silicon Valley
Where are you calling this? In which view? Is that the view being displayed? Have you used the debugger to see if your code is getting called?
__________________
Apple II+, Mac 128k->512ke, Duo 210, MacBook Air 11, iPad mini, iPhone 5
firewood is offline   0 Reply With Quote
Old Jul 23, 2008, 09:32 PM   #3
seventoes
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
Quote:
Originally Posted by firewood View Post
Where are you calling this? In which view? Is that the view being displayed? Have you used the debugger to see if your code is getting called?
Doh. I'm dumb

Code wasnt even being called. Thanks for the little bump :P
seventoes is offline   0 Reply With Quote
Old Jul 24, 2008, 12:30 AM   #4
Sbrocket
macrumors 65816
 
Sbrocket's Avatar
 
Join Date: Jun 2007
Location: /dev/null
You don't want to set the bounds of your button like you are - you want the frame.

Code:
startButton.frame = CGRectMake(120, 200, 80, 20);
Read this page for more info on the distinction:
http://developer.apple.com/documenta...section_3.html

Keep in mind that 0,0 on the iPhone coordinate system is the top-left, not bottom-left (unlike is reflected in that article).
__________________

Unibody MBP 15" | 2.53GHz | 4GB DDR3 | 320GB @ 7200RPM
Sbrocket is offline   0 Reply With Quote
Old Jul 24, 2008, 12:33 AM   #5
seventoes
Thread Starter
macrumors newbie
 
Join Date: Feb 2008
Quote:
Originally Posted by Sbrocket View Post
You don't want to set the bounds of your button like you are - you want the frame.

Code:
startButton.frame = CGRectMake(120, 200, 80, 20);
Read this page for more info on the distinction:
http://developer.apple.com/documenta...section_3.html

Keep in mind that 0,0 on the iPhone coordinate system is the top-left, not bottom-left (unlike is reflected in that article).
Aha, i was wondering why the button liked to chill in the corner there, hehe.. Thanks for the tip!
seventoes is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Animation a UIButton while animating a View - Ipad ashwinr87 iPhone/iPad Programming 3 May 25, 2011 09:56 AM
[Beginner] Adding a UIPickerView to a view yyy iPhone/iPad Programming 2 May 25, 2010 12:59 PM
switch control in table view programatically sultankeshwar iPhone/iPad Programming 0 May 19, 2009 12:47 AM
Loading a Sub View Programatically Lakario iPhone/iPad Programming 2 Nov 7, 2008 08:52 AM
adding more columns to list view schmintan OS X 5 Mar 17, 2007 06:42 AM


All times are GMT -5. The time now is 08:43 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC