【发布时间】:2016-05-19 00:17:06
【问题描述】:
如何在 iOS 中创建水平的UIScrollView 使其看起来像图像?
float width = self.view.frame.size.width/3;
int x = width;
float height = scrCategory.frame.size.height;
for(int i = 0;i<arrCategory.count;i++)
{
UIButton *btnCategory = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnCategory.frame = CGRectMake(x, 0, width, height);
[btnCategory setTag:i+1];
[btnCategory setTitle:[NSString stringWithFormat:@"%@",[arrCategory objectAtIndex:i]] forState:UIControlStateNormal];
[btnCategory setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btnCategory addTarget:self action:@selector(btnCategoryAction:) forControlEvents:UIControlEventTouchUpInside];
[btnCategory setBackgroundColor:[UIColor blackColor]];
[scrCategory addSubview:btnCategory];
x = x + width;
}
[scrCategory setContentSize:CGSizeMake(x+width, height)];
【问题讨论】:
-
到目前为止你尝试了什么?
-
你能把你的代码贴出来吗?
-
在ScrollView中创建多个标签,并设置它们的宽度。
-
@khuong291 我也做到了..
-
你设置了scrollview的宽度吗?
标签: ios objective-c cocoa-touch uiscrollview