2011-07-09 117 views
2
- (void)viewDidLoad { 
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)]; 
tapGesture.numberOfTapsRequired = 1; 
tapGesture.numberOfTouchesRequired = 1; 

[email protected]"Evolution"; 
scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; 

int numberOfImages = 32; 
CGFloat currentX = 0.0f; 

for (int i=1; i <= numberOfImages; i++) { 

    // create image 
    NSString *imageName = [NSString stringWithFormat:@"page-%d.jpg", i]; 
    UIImage *image = [UIImage imageNamed:imageName]; 
    imageView = [[UIImageView alloc] initWithImage:image]; 

    // put image on correct position 
    CGRect rect = imageView.frame; 
    rect.origin.x = currentX; 
    imageView.frame = rect; 
    imageView.tag=i; 
    // update currentX 
    currentX +=454; //mageView.frame.size.width; 

    [scrollView addSubview:imageView]; 
    [imageView release]; 
} 
[scrollView addGestureRecognizer:tapGesture]; 

scrollView.contentSize = CGSizeMake(currentX, 800); 
scrollView.pagingEnabled=YES; 
scrollView.userInteractionEnabled = YES; 
scrollView.maximumZoomScale = 15; 
scrollView.minimumZoomScale = 0.5; 
scrollView.bounces = NO; 
scrollView.bouncesZoom = NO; 
scrollView.delegate = self; 

scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 
[self.view addSubview:scrollView]; 
[scrollView release]; 
[super viewDidLoad]; 
} 

在上面的代碼如何爲每個圖像設置標籤?以便我可以使用該標記從Web服務調用更大的圖像作爲參考。如何在圖像視圖中設置圖像的標籤?

回答

2
imageView.image.tag=i; 

OR

[imageView.image setTag:i]; 
+0

是否圖像標籤意味着,我們可以數點imageviews?我們可以使用這個標籤重新排列圖片嗎? Neenga madurai ya .... ada namma ooru ... !! –

+0

@Ajitthala :) :) –

0

一般來說,我們可以這樣寫:

imgview.image.tag=i; 
相關問題