我需要将 UIButtons 放在 UIScrollView 上。我拥有的代码有效,但是根据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
坐在 a 上,UIScrollView
所以如果有更多UIScrollView
's也应该增长,所以如果有 30+ ,按钮可以滚动到屏幕外。contentSize
dataItems
dataItems