首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何向UIButton添加UIButton

如何向UIButton添加UIButton
EN

Stack Overflow用户
提问于 2012-12-14 20:45:20
回答 3查看 109关注 0票数 0

如何在UIButton上添加UIButton?

这样,如果我移动父UIButton,上面的那个也会移动。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-12-14 20:50:30

代码语言:javascript
复制
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];
票数 2
EN

Stack Overflow用户

发布于 2012-12-14 20:48:32

代码语言:javascript
复制
[oneButton addSubview:otherButton];

请记住,UIButtonUIView的子类...

票数 0
EN

Stack Overflow用户

发布于 2012-12-14 20:49:09

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13878980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档