[英]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];
请记住, UIButton
是UIView
的子类......
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.