[英]UIScrollView paging with buttons
我想知道如何創建帶有按鈕作為對象的頁面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);
}
任何教程,將不勝感激:)
您將只添加按鈕而不是圖像
取代這個
UIImageView *subview = [[UIImageView alloc] initWithFrame:frame];
subview.image = [pictures objectAtIndex:i];
[self.scrollView addSubview:subview];
用
UIButton *subview = [UIButton buttonWithType:UIButtonTypeRoundedRect];
subview.frame = frame;
[subview setTitle:@"Test" forState:UIControlStateNormal];
[self.scrollView addSubview:subview];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.