2

我已经在滚动视图中以编程方式将 Uibutton 创建为网格。现在我需要将 UIbutton 标题拖放到另一个按钮。但原始按钮标题应该保持不变。我搜索了 stackoverflow 我找到了将原始按钮或标签拖动到新位置的选项。请有人帮我解决这个问题。谢谢

int x=0;
int y = 20;
for (int i=0; i<20; i++) //20 = total button
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"TEXT" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(dragOut:withEvent:)forControlEvents:UIControlEventTouchDragOutside |UIControlEventTouchDragInside];

    btn.frame = CGRectMake(10+x,y, 100, 100);
    x=x+70;
    [self.scrollView addSubview:btn];
    if((i+1)%4==0)//4 means how many buttons you need for a row
    {
        y+=110;
        x=0;
    }
}


[self.scrollView setContentSize:CGSizeMake(300, y)];
4

0 回答 0