gpt4 book ai didi

objective-c - UIScrollView 带按钮分页

转载 作者:行者123 更新时间:2023-11-29 04:36:25 25 4
gpt4 key购买 nike

我想知道如何创建一个以按钮为对象的分页 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];

关于objective-c - UIScrollView 带按钮分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11013430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com