简体   繁体   English

在它们之间一定距离处创建UIbutton

[英]Create UIbuttons at a certain distance between them

I made an app which has got API support for developers. 我制作了一个为开发人员提供API支持的应用程序。 Developer who want to make a plugin for my app just have to call a method " -(void)createToggle " and an UIButton will be automatically added to my application's view. 想要为我的应用制作插件的开发人员只需调用方法“-(void)createToggle”,UIButton将自动添加到我的应用视图中。 The problem is that I don't know how to implement in " -(void)createToggle " a way to make UIButtons with a certain distance (180 in this case) between them. 问题是我不知道如何在“-(void)createToggle”中实现一种使UIButton之间具有一定距离(在这种情况下为180)的方法。

I made a loop to do that, here you can see the code: 我做了一个循环来做到这一点,在这里您可以看到代码:

-(void)createToggle 
{
    for (unsigned int i=0; i<[[SPUtils dylibs] count]; i++) 
    {

        toggle = [UIButton buttonWithType:UIButtonTypeCustom];
        toggle.frame = CGRectMake(3487+180 *i, 27, 100, 100); 
        [toggle addTarget:self action:@selector(buttonTarget:) forControlEvents:UIControlEventTouchUpInside];
        [toggleScroll addSubview:toggle];

    }
}

You could paste the snippet here. 您可以在此处粘贴代码段。 The problem seems to be on line: 问题似乎在网上:

toggle.frame = CGRectMake(3487+180 *i, 27, 100, 100);

3487 is a big number. 3487是个很大的数字。 Where the buttons are going to be placed? 按钮将放置在哪里? iPhone has a horizontal range of 0->320 for x. iPhone的x水平范围为0-> 320。 Try this instead: 尝试以下方法:

float margin=180;
float buttonWidth=100;
toggle.frame = CGRectMake(margin+i*buttonWidth+i*margin, 27, 100, 100);

Let me know if it's solved. 让我知道是否解决了。

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

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