我一直在尝试制作一个 100x100 像素的滚动视图(分页模式),以每页 75x75 显示单个按钮。我可以让第一张图片出现,但我无法翻到下一张。这是我一直在使用的代码,有人可以帮助我吗?
。H
@property (nonatomic , retain) IBOutlet UIScrollView *scrollMenu;
.m
@synthesize scrollMenu;
-(void)viewDidLoad {
scrollMenu.pagingEnabled = YES;
NSInteger numberOfButtons = 2;
for (int i = 0; i < numberOfButtons; i++) {
//Array of images for the buttons
NSArray *menuItems = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"1.png"], [UIImage imageNamed:@"2.png"], nil];
//Create A Button
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//Give the button an action
[button addTarget:self action:@selector(menuItemSelected:) forControlEvents:UIControlEventTouchUpInside];
//Give the button an image
[button setImage:[menuItems objectAtIndex:i] forState:UIControlStateNormal];
//Most likely WRONG
button.frame = CGRectMake(i*(20+75), 8.0, 75, 75);
button.showsTouchWhenHighlighted=YES;
//Assign a tag
button.tag = i;
//Add the button to the view
[scrollMenu addSubview:button];
}
//Most likely WRONG
scrollMenu.contentSize = CGSizeMake(100,100);
[self.view addSubview:scrollMenu];
}
[super viewDidLoad];
}