簡體   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