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, iPhone 5, iPad Mini Retina
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

Similar Threads
thread Thread Starter Forum Replies Last Post
iPad: Superclass UIButton Kevvaere iOS 6 1 Feb 26, 2014 06:42 AM
Set font size for all text views programatically moonman239 iPhone/iPad Programming 15 Feb 26, 2013 09:42 PM
Printer connection in iphone Programatically manga iPhone 1 Jan 30, 2013 01:32 AM
How to get the latest downloaded file name with applescript programatically? madhusudhanjr Mac Programming 1 Oct 19, 2012 02:54 PM
Adding/Modifying custom words programatically to iOS dictionary from a csv file ashwinr87 iPhone/iPad Programming 1 Sep 27, 2012 11:38 AM

Forum Jump

All times are GMT -5. The time now is 04:12 AM.

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

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