Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @implementation webViewController
- const CGFloat kScrollObjHeight = 199.0;
- const CGFloat kScrollObjWidth = 280.0;
- const NSUInteger kNumImages = 5;
- @synthesize webView;
- @synthesize scrollView1;
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- NSURL *url = [NSURL fileURLWithPath:[ [ NSBundle mainBundle ] pathForResource: @"htdocs-forzani-1/index" ofType:@"html" ]];
- NSURLRequest *request = [NSURLRequest requestWithURL:url];
- [webView loadRequest:request];
- }
- -(void)scrollView{
- self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
- //setup the scrollview for multiple images and add it to the view controller
- [scrollView1 setBackgroundColor:[UIColor blackColor]];
- [scrollView1 setCanCancelContentTouches:NO];
- scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
- scrollView1.clipsToBounds = YES;
- scrollView1.scrollEnabled = YES;
- scrollView1.userInteractionEnabled = YES;
- scrollView1.pagingEnabled = YES;
- // load all the images
- 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];
- imageView.userInteractionEnabled = YES;
- CGRect rect = imageView.frame;
- rect.size.height = kScrollObjHeight;
- rect.size.width = kScrollObjWidth;
- imageView.frame = rect;
- imageView.tag = i;
- [scrollView1 addSubview:imageView];
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- //[btn setTitle:@"testteeet" forState:UIControlStateNormal];
- [btn setTitle:[NSString stringWithFormat:@"MyButton %d", i] forState:UIControlStateNormal];
- btn.frame = rect;
- [btn setTag:i];
- [btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
- [imageView addSubview:btn];
- // [btn addSubview:lbl];
- }
- [self layoutScrollImages]; // now place the photos in serial layout within the scrollview
- }
- - (void)layoutScrollImages
- {
- UIImageView *view = nil;
- NSArray *subviews = [scrollView1 subviews];
- // reposition all image subviews in a horizontal
- 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;
- }
- }
- // set the content size so it can be scrollable
- [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
- }
Add Comment
Please, Sign In to add comment