space between buttons iPhone SDK

space between buttons iPhone SDK

Hi, can any one please explain how to add space between UIButtons in iPhone SDK. Actually i am creating Multiple UIButton's and added them to my UIScrollView. But problem is that those buttons are placed over each other. Please tell me how can i set fix margin between buttons.

Thanks!

View Answers

January 7, 2011 at 5:47 PM

//Creating UIButtons
    int offset = 0;
    for (int row = 0; row<10; row++){
        for (int col = 0; col<2;col++) {
            offset +=0;

            UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            aButton.frame = CGRectMake(5+col*150+offset,10+row*190, 160, 180);
            aButton.bounds = CGRectMake(5, 0, 140.0, 180.0);

            UIImage *buttonImageNormal = [UIImage imageNamed:@"button3.png"];
            [aButton setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];

            [aButton setTitle:@"Play" forState:UIControlStateNormal];
            [aButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];    


            [self.iScrollView addSubview:aButton];
        }
    }

March 27, 2011 at 9:02 AM

Hello,

Can you please comment the code, I do not understand how the code helps, I am trying to create a multiple buttons on only the x axis and want to include spaces between each button, this is what i have so far can anyone help.

NSMutableArray* buttonArray = [[NSMutableArray alloc] init];

int offset = 0;

for(int i = 0; i < 6; i++) {

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[btn setFrame:CGRectMake((0+offset), 0, 55, 55)];

[btn setTitle:[NSString stringWithFormat:@"Button %d", i+1] forState:UIControlStateNormal];

[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

[buttonArray addObject:btn];

//move button by offset offset += 10;

[btn release];

}

Can anyone help?


March 27, 2011 at 9:03 AM

sorry the offset += 10; is not commented just posted like that see below agin for correct code

NSMutableArray* buttonArray = [[NSMutableArray alloc] init];

int offset = 0;

for(int i = 0; i < 6; i++) {

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[btn setFrame:CGRectMake((0+offset), 0, 55, 55)];

[btn setTitle:[NSString stringWithFormat:@"Button %d", i+1] forState:UIControlStateNormal];

[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

[buttonArray addObject:btn];

//move button by offset offset += 10;

[btn release];

}


March 27, 2011 at 9:04 AM

NSMutableArray* buttonArray = [[NSMutableArray alloc] init];

int offset = 0;

for(int i = 0; i < 6; i++) {

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[btn setFrame:CGRectMake((0+offset), 0, 55, 55)];

[btn setTitle:[NSString stringWithFormat:@"Button %d", i+1] forState:UIControlStateNormal];

[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

[buttonArray addObject:btn];

offset += 10;

[btn release];

}









Related Tutorials/Questions & Answers:
space between buttons iPhone SDK
space between buttons iPhone SDK  Hi, can any one please explain how to add space between UIButtons in iPhone SDK. Actually i am creating Multiple UIButton's and added them to my UIScrollView. But problem is that those buttons
space around/between my images
space around/between my images  How do I eliminate the space around/between my images
Advertisements
creating dynamic buttons in iphone
creating dynamic buttons in iphone  i Have a UIView and i wanted to create a multiple buttons to that should come on view load. It will be great if that can be removed after sometime or required time.   -(void
how to create directed line between two buttons when i clicked there
how to create directed line between two buttons when i clicked there  Hi I have to create a topology between 6 nodes. 6 nodes are created as 6 buttons and when i clicked in first button and then on second button a directed
what is json in iphone sdk
what is json in iphone sdk  What is json in iphone sdk? Is this a library and when i need to include JSon in my iPhone SDK App
Buttons
Buttons  I have created a web page with radio button group with two radio buttons for accepting the home appliances categories,Kitchen appliances and other appliances.I want to check for the appliance chosen when the required
What is iPhone SDK?
What is iPhone SDK?       What is iPhone SDK? The iPhone SDK or iPhone software... and build the software for the iPhone. The iPhone SDK includes the API and components
iPhone SDK UIAlertView
iPhone SDK UIAlertView  Hi, How can i use the iPhone UIAlertView to create a message box. Can any help or provide example or online reference. Thanks
iphone sdk-objective c
iphone sdk-objective c  how to delete random value which is got from the random function in an array
How to remove the space between a JComponent and its Grid border while using GridBagLayout?
How to remove the space between a JComponent and its Grid border while using... space between the Label text and the TextBox.Could anyone help me to reduce the space between those Components? Thanks for ur help in advance.   import
Iphone SDK Development
Iphone SDK Development  Hi, I am a beginner in the Mobile applications platform. From where i get the online help or information related to Iphone SDK Development Apps help. Please provides me reference sites.. Thanks
activity indicator for iphone sdk
activity indicator for iphone sdk  Setting the UIActivity indicator in search bar for iPhone SDK.   [NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil];   -(void
implement core data iphone sdk
implement core data iphone sdk  How to implement core data in iPhone SDK? Please Help
iPhone SDK Examples
. are presented here. We will discuss all the UI and other components of the iPhone SDK...While developing the iPhone program, many times you need some code to copy... components. Windows Buttons Fonts Text Orientation
iPhone SDK Multiple UIButton
iPhone SDK Multiple UIButton  In my iphone SDK program.. i wanted... into database. Any help is appreciated. Thanks in Advance!   iPhone SDK...:myButton]; iPhone SDK Creating Multiple UIButton for (int row = 0; row<4
Page curl effect iPhone SDK
Page curl effect iPhone SDK  How to get the page curl effect in my iPhone application? Please suggest or give an example to get the page curl effect in iPhone SDK application. Thanks.   In objective c there is a method
Hyperlink on UILabel iPhone SDK
Hyperlink on UILabel iPhone SDK  Hi, I wanted to set a hyperlink on UILabel in my iPhone application. Can anyone suggest me how to do it? Thanks
iPhone Capturing Screen SDK
iPhone Capturing Screen SDK  Creating an application to capture the screen shots from iPhone. In objective c is there any class that make it enable..?   UIGraphicsBeginImageContext(CGSizeMake(480,320)); UIImage* result
share data iphone sdk
share data iphone sdk  How to share data in iPhone application? Actually i want the sharing feature in my iPhone application. Thanks!   You can use the emailing feature in your iPhone application to the share data
parse url iphone sdk
parse url iphone sdk  How can i parse two different URL's using NSXMLParser
iPhone SDK Tutorials and Examples
The best collection of iPhone development tutorials and examples specially developed to learn iPhone SDK programming easily. These iPhone SDK tutorials... we will explain you the iPhone SDK programming concepts in detail. You
Installing iPhone SDK
Downloading and Installing iPhone SDK?       Downloading SDK for iPhone... should see a link to ?iPhone SDK for iPhone OS 2.2.? Click on this link
iPhone 3.0 SDK
iPhone 3.0 SDK delivers on its Promise  ... release is the beta version of the third iPhone SDK. The iPhone 3.0 SDK beta allows... (PNS) feature, included in the iPhone 3.0 SDK release. The PNS allows third party
iphone
iphone  hiii, how can we use table recursively in iphone
license for google maps - iPhone SDK
license for google maps - iPhone SDK  Do i need a license to display the locations on google map in my iPhone application
go back to previous view iphone sdk
go back to previous view iphone sdk  How to go back to previous view iphone sdk?    - (IBAction)backView:(id)sender { [self.navigationController popViewControllerAnimated:YES
How to open URL in iPhone SDK
How to open URL in iPhone SDK  In my iPhone application ..i wanted to open a url in the application. Is it possible? If yes how will i come back to my application
Set Space Ratio and Alignment
alignment. You can make pdf with no space between the characters of a word...: If you want the alignment to be justified, the space between the words can be stretched, as well as the space between the characters of a word
iphone
iphone  How can connect with the other database in iphone application(like... MYsql or oracle) is this dirctly possible
iphone
iphone  hello... i want to make first iphone application . How can i make it plz help me
iPhone Game Applications Development, iPhone Game Porting Services, iPhone Game Designing
Services Rose India can develop games using the iPhone SDK... iPhone Game Applications Development iPhone Game Development... the way we listen to music and download it, the iPhone has revolutionalized mobile
add plist file iphone sdk
add plist file iphone sdk  how to add plist file in XCode
add plist file iphone sdk
add plist file iphone sdk  how to add plist file in XCode
rate my app iphone SDK
rate my app iphone SDK  How can i enable "Rate and Review Application" feature of my application on iTune
How do SEL and @selector work in iphone sdk?
How do SEL and @selector work in iphone sdk?  How do SEL and @selector work in iphone sdk?   SEL is a type that represents a selector in Objective-C. The @selector() keyword returns a SEL that you describe
remove from superview iphone sdk
remove from superview iphone sdk  How to remove the old view from super-view and add the new view safely? My main concern is memory leak.. so, please suggest how can i do it without facing a memory leak. Thanks
iPhone Application Development,Mobile iPhone Application Development,iPhone Porting Solutions
the iPhone SDK to add value to your existing applications.ADS... iPhone Application Development Services Rose India iPhone Application Development Services iPhone 3G is Apple developed smartphone
iPhone 3G vs iPhone 2G
Features: We finally come down to the main difference between the iPhone 2G and the iPhone 3G, GPS and 3G. For many these are the real difference between the old... the major differences between the old and the new iPhone. If you really need faster
iPhone SDK Comparing Strings
In this section I will show you how you can compare the two strings in your iPhone SDK Project. To compare the Strings you will have to use...; } The above example is the proper way of comparing strings in iPhone sdk
Current Date iPhone SDK
Current Date iPhone SDK In this example, you'll find out how to get current date & day in iPhone SDK. We'll also write a method to print the day and date...! If not lets first find out what is NSdateFormatter in iPhone SDK programming
Use of SVOX SDK 5.0.0 for text to speech in iphone project
Use of SVOX SDK 5.0.0 for text to speech in iphone project  how to implement svox sdk for text to speech in xcode. I need a sort of exmaple for it...awaitinh ofr your reply thanks
Use of SVOX SDK 5.0.0 for text to speech in iphone project
Use of SVOX SDK 5.0.0 for text to speech in iphone project  how to implement svox sdk for text to speech in xcode. I need a sort of exmaple for it...awaitinh ofr your reply thanks
radio buttons
radio buttons  write a program to create an applet button which has a list of radio buttons with titles of various colours.set the background colour... has a list of radio buttons with titles of various colors and a button
iPhone Application Development
be developed using a variety of tools like Apple's free iPhone SDK development tool... because of the relatively smaller screen size vis-à-vis a PC. iPhone SDK... files in an iPhone simulator or device. The DashCode bundled with the iPhone SDK
iPhone
apps can be developed using a variety of tools like Apple's free iPhone SDK....   iPhone SDK programming Learn iPhone SDK programming... iPhone      
Remove Extra Space At End
Remove Extra Space At End  Remove Extra Space At End
How to write Example code for comparing Strings in iPhone SDK?
How to write Example code for comparing Strings in iPhone SDK?  I have an object of NSString class and I want to compare it with another NSString... at iPhone SDK Comparing Strings. Thanks
add Buttons in JavaScript
add Buttons in JavaScript  How to add Buttons in JavaScript
time and space complexity
time and space complexity  sort the data structures according to efficient time and space utilisation
ModuleNotFoundError: No module named 'space'
ModuleNotFoundError: No module named 'space'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'space' How to remove the ModuleNotFoundError: No module named 'space'

Ads