将多个UIButton添加到UIView [英] Adding multiple UIButtons to an UIView

查看:52
本文介绍了将多个UIButton添加到UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经以编程方式向UIView添加了一些按钮(通过addSubview).但是,它们显示为叠加层(因此,我始终只能看到最后一个按钮).如何在现有按钮下方添加新按钮?

I've added some buttons to an UIView (via addSubview) programmatically. However, they appear as overlays (so that I always see the last button only). How do I add new buttons below existing buttons?

致谢

推荐答案

您可以像这样偏移按钮

int newX = previousButton.frame.origin.x + previousButton.frame.size.width ;
int newY = previousButton.frame.origin.y ;

,并在创建新按钮时为其设置框架:

and either set the frame for new button when you create it:

[[UIButton alloc] initWithFrame:CGRectMake(newX,newY,100,100)];

或稍后设置框架

newButton.frame = CGRectMake(newX,newY,100,100);

这篇关于将多个UIButton添加到UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆