Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

space between buttons iPhone SDK

Ads

 
 

Share on Google+Share on Google+

Java Coder
space between buttons iPhone SDK
4 Answer(s)      6 years and 6 months ago
Posted in : MobileApplications

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!

Ads
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];

}


Ads









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-objective c
iphone sdk-objective c  how to delete random value which is got from the random function in an array
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 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
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
implement core data iphone sdk
implement core data iphone sdk  How to implement core data in iPhone SDK? Please Help
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
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
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.... The Apple's SDK enables the programmers to develop software for iPhone
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..., included in the iPhone 3.0 SDK release. The PNS allows third party servers to send
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
Set Space Ratio and Alignment
alignment. You can make pdf with no space between the characters of a word... the alignment to be justified, the space between the words can be stretched, as well as the space between the characters of a word. The default
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
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