如何将UIButton添加到UIButton中

问题描述:

如何在UIButton上添加UIButton?如何将UIButton添加到UIButton中

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

+1

emmmm .....什么???? – Stas

+0

也许Autolayout是你在找什么。 –

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]; 

[oneButton addSubview:otherButton]; 

记住UIButtonUIView一个子类...

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