Iphone 以编程方式在UIScrollView中添加UIButtons
我是iPhone开发新手,我想知道如何在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
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