Share on Google+Share on Google+

Java Coder
space between buttons iPhone SDK
4 Answer(s)      6 years and 3 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];

}










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
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
Advertisements
iphone sdk-objective c
iphone sdk-objective c  how to delete random value which is got from the random function in an array
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 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
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
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
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
implement core data iphone sdk
implement core data iphone sdk  How to implement core data in iPhone SDK? Please Help
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
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
parse url iphone sdk
parse url iphone sdk  How can i parse two different URL's using NSXMLParser
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
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
space around/between my images
space around/between my images  How do I eliminate the space around/between my images
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 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 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
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
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
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
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
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
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
rate my app iphone SDK
rate my app iphone SDK  How can i enable "Rate and Review Application" feature of my application on iTune
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 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... of comparing strings in iPhone sdk programs. The == operator only compares
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
Tutorials   
Java Spring Hibernate Struts Training How to uninstall old version of Android Studio? How to install cocoapods in Max? item lookup How to get path of a file in iOS? [NSConcreteMutableData release]: message sent to deallocated instance Covert Bool to String - NSString Getting UIButton by Tag How to write Example code for comparing Strings in iPhone SDK? How to set placeholder in uitextfield programmatically? Example code of adding placeholder in UItextFeild how to get UIView by tag J2me image use ase smiley UILineBreakModeWordWrap is deprecated Framework for Mobile Applications How to print UIButton id System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h' has been modified since the precompiled header UINavigationController Navigating to back uinavigationcontroller add right button UINavigationController how to set title uitextfield hide keyboard on return dismissmodalviewcontrolleranimated first deprecated in ios 6.0 xcode 6.1.1 download How to remove virtual keypad from apps java How to remove virtual keypad from apps java How to remove virtual keypad from apps java code to send sms alerts using jsp online iphone app development how to devlop mobile application? What is WAP? download mp3 file on server in iphone home button macbook pro keyboard calling from iphone through programitically in iphone How to retrieve a field from SQLite to Edittext in android How to retrieve a field from SQLite to Edittext in android Sqlite3 Why NSMutableDictionary ios work with nsdictionary what is class methods in objective c what is class methods in objective c UIButton HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE Rad Calculator ANDROID J2ME Bar graph j2me image application iphone iphone

Ads

 
Advertisement null

Ads