Guest User

Untitled

a guest
Jan 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. @implementation webViewController
  3. const CGFloat kScrollObjHeight  = 199.0;
  4. const CGFloat kScrollObjWidth   = 280.0;
  5. const NSUInteger kNumImages     = 5;
  6. @synthesize webView;
  7. @synthesize scrollView1;
  8.  
  9. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  10. {
  11.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  12.     if (self) {
  13.         // Custom initialization
  14.     }
  15.     return self;
  16. }
  17.  
  18. - (void)viewDidLoad
  19. {
  20.     [super viewDidLoad];
  21.    
  22.     NSURL *url = [NSURL fileURLWithPath:[ [ NSBundle mainBundle ] pathForResource: @"htdocs-forzani-1/index" ofType:@"html" ]];
  23.     NSURLRequest *request = [NSURLRequest requestWithURL:url];
  24.     [webView loadRequest:request];
  25.    
  26.    
  27.        
  28.    
  29. }
  30.  
  31. -(void)scrollView{
  32.    
  33.     self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
  34.    
  35.     //setup the scrollview for multiple images and add it to the view controller
  36.    
  37.     [scrollView1 setBackgroundColor:[UIColor blackColor]];
  38.     [scrollView1 setCanCancelContentTouches:NO];
  39.     scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
  40.     scrollView1.clipsToBounds = YES;       
  41.     scrollView1.scrollEnabled = YES;
  42.     scrollView1.userInteractionEnabled = YES;
  43.    
  44.    
  45.     scrollView1.pagingEnabled = YES;
  46.    
  47.     // load all the images
  48.     NSUInteger i;
  49.     for (i = 1; i <= kNumImages; i++)
  50.     {
  51.         NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
  52.        
  53.         UIImage *image = [UIImage imageNamed:imageName];
  54.         UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  55.         imageView.userInteractionEnabled = YES;
  56.        
  57.  
  58.         CGRect rect = imageView.frame;
  59.         rect.size.height = kScrollObjHeight;
  60.         rect.size.width = kScrollObjWidth;
  61.         imageView.frame = rect;
  62.         imageView.tag = i; 
  63.         [scrollView1 addSubview:imageView];
  64.    
  65.    
  66.        
  67.         UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  68.          //[btn setTitle:@"testteeet" forState:UIControlStateNormal];
  69.         [btn setTitle:[NSString stringWithFormat:@"MyButton %d", i] forState:UIControlStateNormal];
  70.        
  71.  
  72.          btn.frame = rect;
  73.          [btn setTag:i];
  74.         [btn addTarget:self action:@selector(buttonClick:)  forControlEvents:UIControlEventTouchUpInside];
  75.  
  76.         [imageView addSubview:btn];
  77.       //  [btn addSubview:lbl];
  78.      
  79.        
  80.     }
  81.    
  82.     [self layoutScrollImages]// now place the photos in serial layout within the scrollview
  83.    
  84.  
  85. }
  86.  
  87.  
  88. - (void)layoutScrollImages
  89. {
  90.     UIImageView *view = nil;
  91.     NSArray *subviews = [scrollView1 subviews];
  92.    
  93.     // reposition all image subviews in a horizontal
  94.     CGFloat curXLoc = 0;
  95.     for (view in subviews)
  96.     {
  97.         if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
  98.         {
  99.             CGRect frame = view.frame;
  100.             frame.origin = CGPointMake(curXLoc, 0);
  101.             frame.size.height = 110;
  102.             frame.size.width = 270;
  103.             frame.origin.y = 10;
  104.        
  105.             view.frame = frame;
  106.             curXLoc += (kScrollObjWidth) + 15;
  107.            
  108.         }
  109.     }
  110.    
  111.     // set the content size so it can be scrollable
  112.     [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
  113. }
Add Comment
Please, Sign In to add comment