2011-07-22 11 views
0

このコードでは、ボタンの代わりに変更を加えたい画像ビューで画像を作成し、画像をズームイン/ズームアウトしたスクロールビューで作成したいと考えています。そして、私はボタンでいくつかのイベントを実装することができるように、すべての画像ビューに2つまたは3つのボタン。それはどうですか?スクロール表示でuibuttonの代わりにスクロール表示でイメージを追加する方法はありますか?

- (void)loadView { 
     [super loadView]; 
     self.view.backgroundColor = [UIColor redColor]; 

     UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,  self.view.frame.size.width, self.view.frame.size.height)]; 
     scroll.pagingEnabled = YES; 

     NSInteger numberOfViews = 33; 
     [btnMenu setTag:0 ]; 
     for (int i = 1; i < numberOfViews; i++) { 
      CGFloat yOrigin = i * self.view.frame.size.width; 
      UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(yOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
      //awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1]; 
      btnMenu = [UIButton buttonWithType:UIButtonTypeCustom]; 
      //NSData *data =UIImageJPEGRepresentation(, 1); 
      [btnMenu setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"page-%d.jpg",i]] forState:UIControlStateNormal]; 

      CGRect frame = btnMenu.frame; 
      frame.size.width=320; 
      frame.size.height=460; 
      frame.origin.x=0; 
      frame.origin.y=0; 
      btnMenu.frame=frame; 

      [btnMenu setTag:i]; 
      btnMenu.alpha = 1; 

      [btnMenu addTarget:self action:@selector(btnSelected:) forControlEvents:UIControlEventTouchUpInside]; 
      [awesomeView addSubview:btnMenu]; 

      [scroll addSubview:awesomeView]; 
      [awesomeView release]; 
     } 
     scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height); 
     [self.view addSubview:scroll]; 
     [scroll release]; 
} 

-(IBAction)btnSelected:(id)sender{ 
    UIButton *button = (UIButton *)sender; 
    int whichButton = button.tag; 
    NSLog(@"Current TAG: %i", whichButton); 
    if(whichButton==1) 
    { 
     first=[[FirstImage alloc]init]; 
     [self.navigationController pushViewController:first animated:YES]; 
    } 

} 
+0

私はまだあなたが何を求めているのか分かりません。あなたの文章は意味をなさない。 – jzd

+0

私は、上記のコードでは、ビューでuibuttonを追加していると言っています。これで、私はスクロール可能な画像を追加したいと思います。 – ram

+0

補足として、あなたの記事に正しい大文字を使用してください。 – jzd

答えて

2

ボタンの代わりにイメージが必要ですか?次に試してみてください:

scroll=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; 
    scroll.backgroundColor=[UIColor clearColor]; 
    scroll.pagingEnabled=YES; 
    scroll.contentSize = CGSizeMake(320*33, 300); 
    CGFloat x=0; 
    for(int i=1;i<34;i++) 
    {   
     UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(x+0, 0, 320, 460)]; 
     [image setImage:[UIImage imageNamed:[NSString stringWithFormat:@"page-%d.jpg",i]]]; 
     [scroll addSubview:image]; 
     [image release]; 
     x+=320; 
    } 
    [self.view addSubview:scroll]; 
    scroll.showsHorizontalScrollIndicator=NO; 
    [scroll release]; 
+0

ズームイン機能とズームアウト機能はどのように適用されますか? – ram

+0

_UIPinchGestureRecognizer_をイメージに適用すると、_UIPinchGestureRecognizer delegate_を使ってズームできます。 – Sisu

関連する問題