UIScrollView に UIButtons を配置する必要があります。私が持っているコードは機能しますが、持っている量によってはdataItems
、間隔が均一ではありません。
問題のスニペット
CGRectMake(10, ((120 / (count + 1)) * (i + 1) * 3) ,300,50)
具体的には
((120 / (count + 1)) * (i + 1) * 3)
作業コード
int count = [dataItems count]; /* not a specific value, can grow */
for (int i = 0; i < count; i++) {
UIButton* aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[aButton setTag:i];
[aButton setFrame: CGRectMake(10,((120 / (count + 1)) * (i + 1) * 3) ,300,50) ];
[aButton setTitle:[[dataItems objectAtIndex:i] objectForKey:@"Feed"] forState:UIControlStateNormal];
[aButton addTarget:self action:@selector(viewCategories:) forControlEvents:UIControlEventTouchUpInside];
[scroller addSubview:aButton];
}
スクリーンショット
右側の例は、間隔に関しては左側の例のように見えるはずです。はのUIButtons
上に座っているUIScrollView
ので、UIScrollView
がcontentSize
さらにある場合は も成長し、dataItems
たとえば 30+ がある場合にボタンが画面外にスクロールできるようにする必要がありますdataItems
。