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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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-10-2010, 07:43 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Darlington UK
Posts: 84
kampftrinker is on a distinguished road
Default Buttons on a scrollview

How do i add a button to a scrollview when there is no NIB involved?

below is the code i thought might work, the scrollview part works fine i just can't see the button. any ideas?

-(void)loadview {
self.scrollview1 = [[UIScrollView alloc] init] autorelease];
self.scrollview1.delegate = self;
self.scrollview1.pagingEnabled = YES;
self.scrollview1.showsHorizontalScrollIndicator = NO;
self.scrollview1.showsVerticalScrollIndicator = NO;
self.view = self.scrollView1;

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 60, 100, 30);
button setTitle:@"Click Me!" forState:UIControlStateNormal];
[self.scrollView1 addSubview:button];
}

Thanks
Mick
kampftrinker is offline   Reply With Quote
Old 07-11-2010, 02:30 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Darlington UK
Posts: 84
kampftrinker is on a distinguished road
Default

Anybody got any ideas?

any help would be much appriciated.

Mick
kampftrinker is offline   Reply With Quote
Old 07-11-2010, 02:38 AM   #3 (permalink)
New to the SDK
 
franzwarning's Avatar
 
Join Date: Jul 2010
Location: Portland, Oregon
Age: 19
Posts: 165
franzwarning is on a distinguished road
Send a message via AIM to franzwarning Send a message via Skype™ to franzwarning
Default

is it roundedrect or roundrect? withouth the roundED.... idk could be the problem....

Last edited by franzwarning; 07-11-2010 at 02:40 AM.
franzwarning is offline   Reply With Quote
Old 07-11-2010, 03:26 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Darlington UK
Posts: 84
kampftrinker is on a distinguished road
Default

Hi, thanks for the reply.
roundedrect is correct, any more ideas?

Mick
kampftrinker is offline   Reply With Quote
Old 07-11-2010, 05:51 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Can you even see the scrollview? You don't give it a frame anywhere, which could be a problem.
harrytheshark is offline   Reply With Quote
Old 07-11-2010, 07:02 AM   #6 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Darlington UK
Posts: 84
kampftrinker is on a distinguished road
Default

Hi, I can see the scrollview and it works fine.
It's just the button that seems to be a problem.

Thanks
Mick
kampftrinker is offline   Reply With Quote
Old 07-11-2010, 07:14 AM   #7 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Using your code in a new project, I cannot see the scrollview or the button. Giving it a frame, I can see both the scrollview and the button.

Something to bare in mind as well is that loadView will not work if you are using a XIB.
Code:
- (void)loadView {
	
	self.scrollview1 = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease]; // Dont hard code values in actual app.
	self.scrollview1.delegate = self;
	self.scrollview1.pagingEnabled = YES; 
	self.scrollview1.showsHorizontalScrollIndicator = NO;
	self.scrollview1.showsVerticalScrollIndicator = NO;
	self.view = self.scrollview1;

	UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	button.frame = CGRectMake(100, 60, 100, 30);
	[button setTitle:@"Click Me!" forState:UIControlStateNormal];
	[button sizeToFit];
	[self.scrollview1 addSubview:button];
}
harrytheshark is offline   Reply With Quote
Old 07-11-2010, 09:15 AM   #8 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Darlington UK
Posts: 84
kampftrinker is on a distinguished road
Default

Hi Harry, thanks for the reply, you are right about the frame that solved the issue. I've tested it without a NIB file and it works, this has highlighted another couple of issues.

My scrollview displays a number of images which i can swipe through. The button moves off screen when i swipe the first image also the button is behind the actual image.

How can i position the button above the image and also stop it scrolling.

Thanks for your help so far.
Mick
kampftrinker is offline   Reply With Quote
Old 07-11-2010, 10:10 AM   #9 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

I would suggest adding the scrollview as a subview to the main view, rather than setting that scrollview as the main view.
Then you would add the button to the main view and not the scrollview. That way it won't scroll and will be on top of the scrollview, providing you add it last.
harrytheshark is offline   Reply With Quote
Old 07-11-2010, 02:19 PM   #10 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: Darlington UK
Posts: 84
kampftrinker is on a distinguished road
Default

Thanks for that Harry, it's working now.

Mick
kampftrinker 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: 325
14 members and 311 guests
akphyo, alexP, cgokey, EXOPTENDAELAX, flamingliquid, guusleijsten, ohmniac, Paul Slocum, PavelSea, SLIC, Sloshmonster, Sonuye857, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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