繁体   English   中英

如何将UIButton添加到UIButton

[英]How to add a UIButton to a UIButton

如何在UIButton上添加UIButton?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM