Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-29-2010, 06:37 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Ohio
Posts: 27
Default Setting Buttons in a ScrollView

Hello there,

I have a viewController with a .xib that includes a header image at the top of the screen, and a scroll view at the bottom of the screen. I can scroll up and down through the image I have set in the scroll view, what I would like to do is create a bunch of different clickable areas within that scroll view.

SEE IMAGE:
https://www.dropbox.com/s/e6bo7zqzsltp9y2/clickArea.png

Can anybody recommend the best way to go about creating buttons that are clickable on each of those green areas?

Would I create buttons programmatically and place them at the proper x,y coordinate so they can be placed in the scrollView even in the areas not visible on load, but only visible when they are scrolled down to?

How do I create buttons that are INSIDE the scrollview?

Right now, I have, in the header file:
IBOutlet UIScrollView *scrollView;
@property (nonatomic, retain) UIView *scrollView;

and in the .m file in viewDidLoad:
[scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.clipsToBounds = YES;
scrollView.indicatorStyle = UIScrollViewIndicatorStyleBlack;
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"clickAreas.png"]];
[scrollView addSubview:imageView];
[scrollView setContentSize:CGSizeMake(imageView.frame.size.wid th, imageView.frame.size.height)];
[scrollView setScrollEnabled:YES];
[imageView release];

This loads the image and allows me to scroll through it, just not sure how to add buttons so that each of those areas can be clicked.

THANK YOU VERY MUCH IN ADVANCE FOR YOUR HELP! ^_^
Attached Images
File Type: jpg clickAreas.jpg (3.3 KB, 0 views)

Last edited by 965Studios; 07-29-2010 at 06:47 PM.
965Studios is offline   Reply With Quote
Old 07-29-2010, 11:21 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Ohio
Posts: 27
Default Here's what I ended up doing..

If anyone is interested, here is what I ended up doing:

//Choose the image for the button
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sp6-1.png"]];

//Position it at the x,y desired
CGRect sixFrame = CGRectMake(30, 18, imageView.frame.size.width, imageView.frame.size.height);
imageView.frame = sixFrame;

// Buttons are defined in .h as such:
// UIButton *sP1Btn;

//Programmatically add the button to the screen, set its frame, image, and action when tapped:
sP1Btn = [UIButton buttonWithType:UIButtonTypeCustom];
sP1Btn.frame = sixFrame;
[sP1Btn setBackgroundImage:imageView.image forState:UIControlStateNormal & UIControlStateHighlighted & UIControlStateSelected];
[sP1Btn addTarget:self action:@selector(sP1Tapped: ) forControlEvents:UIControlEventTouchUpInside];

// Add the button (as a subview) to my scrollView and release the variable:
[scrollView addSubview:sPea1Btn];
[imageView release];
965Studios is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 269
19 members and 250 guests
2WeeksToGo, @sandris, AdamL, ADY, Dani77, diyora, F_Bryant, GHuebner, HDshot, headkaze, mer10, Oral B, prchn4christ, Rudy, smithdale87, Thompson22, timle8n1, Touchmint, vigu360
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,748
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:56 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0