1 Replies - 30502 Views - Last Post: 08 October 2012 - 11:43 AM

#1 justin78  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 07-October 12

load scrollview from button(objective-C)

Posted 08 October 2012 - 11:40 AM

I have an UIWebView page with one button. On this page I have an UIscrollView, and I want to load this scroll view when I press the button. Would you please give me some hint for implementing this?


here is the code:

-(void)scrollView{
    
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
    
	[scrollView1 setBackgroundColor:[UIColor blackColor]];
	[scrollView1 setCanCancelContentTouches:NO];
	scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
	scrollView1.clipsToBounds = YES;		
	scrollView1.scrollEnabled = YES;
	

	
	scrollView1.pagingEnabled = YES;
	
	NSUInteger i;
	for (i = 1; i <= kNumImages; i++)
	{
		NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
		UIImage *image = [UIImage imageNamed:imageName];
		UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
		
		
		CGRect rect = imageView.frame;
		rect.size.height = kScrollObjHeight;
		rect.size.width = kScrollObjWidth;
		imageView.frame = rect;
		imageView.tag = i;	
		[scrollView1 addSubview:imageView];
        
	}
	
	[self layoutScrollImages];	
    

}


- (void)layoutScrollImages
{
	UIImageView *view = nil;
	NSArray *subviews = [scrollView1 subviews];
    
	
	CGFloat curXLoc = 0;
	for (view in subviews)
	{
		if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
		{
			CGRect frame = view.frame;
			frame.origin = CGPointMake(curXLoc, 0);
            frame.size.height = 110;
            frame.size.width = 270;
            frame.origin.y = 10;
        
			view.frame = frame;
			curXLoc += (kScrollObjWidth) + 15;
			
		}
	}
	
	
	[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}



// my button for load UIScrollView


- (IBAction)openAction:(id)sender {

}



Is This A Good Question/Topic? 0
  • +

Replies To: load scrollview from button(objective-C)

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10649
  • View blog
  • Posts: 39,548
  • Joined: 27-December 08

Re: load scrollview from button(objective-C)

Posted 08 October 2012 - 11:43 AM

Just an FYI- in the future, please avoid duplicate posting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1