0
我想知道如何創建一個分頁UIScrollView與按鈕作爲對象?UIScrollView分頁與按鈕
到目前爲止,我已經想通了,以與圖像,而不是它看起來像這樣類似的UIScrollView:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *pictures = [NSArray arrayWithObjects: [UIImage imageNamed:@"nr1"], [UIImage imageNamed:@"nr2"], nil];
for (int i = 0; i < pictures.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
subview.image = [pictures objectAtIndex:i];
[self.scrollView addSubview:subview];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * pictures.count, self.scrollView.frame.size.height);
}
任何教程,將不勝感激:)
謝謝,這真的有幫助。但是,我如何使用這種方法創建多個按鈕,以及如何將按鈕鏈接到IBAction? – user1411094
您可以創建一個字典或一組按鈕。也可以嘗試將標籤設置到按鈕上,以便您可以區分各個按鈕的相應操作。 – Kimpoy