0

如何在 UIButton 上添加 UIButton?

这样,如果我移动父 UIButton 顶部的 UIButton 也会移动。

4

3 回答 3

2
UIButton *testButton = [UIButton buttonWithType:UIButtonTypeCustom];
testButton.backgroundColor = [UIColor redColor];

UIButton *smallerButton = [UIButton buttonWithType:UIButtonTypeCustom];
smallerButton.backgroundColor = [UIColor greenColor];
[testButton addSubview:smallerButton];

[self.view addSubview:testButton];
于 2012-12-14T12:50:30.147 回答
0
[oneButton addSubview:otherButton];

请记住,这UIButtonUIView...的子类

于 2012-12-14T12:48:31.877 回答
0
UIButton *parentBtn;
UIButton *childBtn;

parentBtn = [UIButton buttonWithType: // init the button];
childBtn = //same for child btn

[self.view addSubview:parentBtn]; //add the parent button to the view
[parentBtn addSubview:childBtn]; //add the child button on top of the parent button
于 2012-12-14T12:49:08.827 回答