我对UIButton的“Touch Up Inside”事件具有此操作,该事件应在发送方的正下方创建一个新的UIButton:

-(IBAction) cloneMe: (id) sender{

    if (!currentY) {
        currentY = [sender frame].origin.y;
    }

    UIButton *clone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    CGRect cloneFrame = [sender frame];
    cloneFrame.origin.y += currentY + cloneFrame.size.height + 30;
    clone.frame = cloneFrame;

    currentY = cloneFrame.origin.y + cloneFrame.size.height;


}

它不起作用,并且永远不会显示新按钮。有人知道发生了什么吗?

最佳答案

您忘记了[sender.superview addSubview:clone];

关于objective-c - 使用Cocoa Touch在运行时创建控件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4401864/

10-11 14:33