Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 以编程方式在UIScrollView中添加UIButtons_Iphone_Objective C_Ipad_Uiscrollview_Uibutton - Fatal编程技术网

Iphone 以编程方式在UIScrollView中添加UIButtons

Iphone 以编程方式在UIScrollView中添加UIButtons,iphone,objective-c,ipad,uiscrollview,uibutton,Iphone,Objective C,Ipad,Uiscrollview,Uibutton,我是iPhone开发新手,我想知道如何在UIScrollView中添加UIButtons 这些按钮的范围应从12到20,24,28等 是否有任何代码可以动态执行此操作,而不是从Nib文件执行此操作,并且是否有可用的示例 提前感谢。当然,您可以通过以下方式手动添加按钮: [scrollView addSubview:yourButton]; 您可以通过IB创建这两个东西并设置按钮的帧vía代码您可以这样做: [self.scrollView setScrollEnabled:YES]; [sel

我是iPhone开发新手,我想知道如何在
UIScrollView
中添加
UIButton
s

这些按钮的范围应从
12
20
24
28

是否有任何代码可以动态执行此操作,而不是从Nib文件执行此操作,并且是否有可用的示例


提前感谢。

当然,您可以通过以下方式手动添加按钮:

[scrollView addSubview:yourButton];
您可以通过IB创建这两个东西并设置按钮的帧vía代码

您可以这样做:

[self.scrollView setScrollEnabled:YES];
[self.scrollView setFrame:CGRectMake(0, 70,320, 70)];
[self.scrollView setContentSize:CGSizeMake(2370, 70)];

int x = 0;
for (int i=0; i<[your array count]; i++) {

    // view allocation
    ButnView=[[UIView alloc] init];
    [ButnView setFrame:CGRectMake(x, 0, 82, 70)];

    // label allocation
    UILabel* butnheaderlabel = [[UILabel alloc] initWithFrame:CGRectMake(14, -10, 80, 70)];
    UILabel* butnfooterlabel  = [[UILabel alloc] initWithFrame:CGRectMake(27, 10, 80,70)];
    [butnheaderlabel setFont:[UIFont systemFontOfSize:14.0]];

    // button allocation
    btn=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(0, 0,82, 70)];
    [btn setBackgroundColor:[UIColor clearColor]];
    [btn setTag:i];
    [[btn layer] setBorderWidth:1.0f];
    [[btn layer] setBorderColor:[UIColor grayColor].CGColor];
    NSString*resourceKey=[your array objectAtIndex:i];
    NSArray*seperatedStr=[resourceKey componentsSeparatedByString:@","];
    [btn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [btn addSubview:butnheaderlabel];
    [btn addSubview:butnfooterlabel];
    [ButnView addSubview:btn];
    [self.scrollView addSubview:ButnView];
    x+=81;
}
[self.scrollView设置可滚动:是];
[self.scrollView setFrame:CGRectMake(070320,70)];
[self.scrollView setContentSize:CGSizeMake(2370,70)];
int x=0;
对于(int i=0;i