小编joh*_*ike的帖子

在iOS中按钮的水平滚动

我已经使用按钮实现了以下水平滚动,但它似乎只在5秒后开始滚动.它卡住了.我想,UI会被阻止.

我有以下代码来创建我的 ViewDidLoad()

 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height-100, self.view.frame.size.width, 100)];

    int x = 10;
    for (int i = 0; i < 10; i++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x,10,80,80)];
        [button setTitle:[NSString stringWithFormat:@"Button %d", i] forState:UIControlStateNormal];
        [button setTag:i];
        [button setBackgroundColor:[UIColor greenColor]];
        [button addTarget:self action:@selector(onClickofFilter:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:button];

        x += button.frame.size.width+10;
    }

    scrollView.contentSize = CGSizeMake(x, scrollView.frame.size.height);
    scrollView.backgroundColor = [UIColor redColor];

    [self.view addSubview:scrollView];
Run Code Online (Sandbox Code Playgroud)

显示绿色按钮行的图象在红色背景的.

有没有办法使它顺利?

objective-c uibutton uiscrollview ios

2
推荐指数
1
解决办法
6767
查看次数

标签 统计

ios ×1

objective-c ×1

uibutton ×1

uiscrollview ×1