私はiPhone開発の初心者です。UIScrollView
にUIButton
を追加するにはどうすればいいですか?UIScrollViewでUIBcuttonをプログラムで追加する
これらのボタンは28
、24
、12
から20
に変わるべきであるなど
は、我々がないnibファイルから、動的にこれを行うことができることから、任意のコードがあり、いずれのサンプルがavaliableありますか?
ありがとうございます。
私はiPhone開発の初心者です。UIScrollView
にUIButton
を追加するにはどうすればいいですか?UIScrollViewでUIBcuttonをプログラムで追加する
これらのボタンは28
、24
、12
から20
に変わるべきであるなど
は、我々がないnibファイルから、動的にこれを行うことができることから、任意のコードがあり、いずれのサンプルがavaliableありますか?
ありがとうございます。
次のようなもので、手動でボタンを追加することができ、確かに:
[scrollView addSubview:yourButton];
あなたは、このように行うことができIBを経由して、両方のものを作成して、ボタンのフレームのVIAコード
を設定することができます。
[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;
}