我正在使用带有滚动功能的pagecontrol。
在该页面控件中,我创建了3个标签和两个按钮。
现在我想在点击按钮时执行功能。我该如何识别
执行ButtonClick事件时的当前页面。
点击按钮,我想显示另一个已经创建的标签
它被隐藏的时间。请指导我。
这是在pagecontrol中创建对象的代码:
UILabel *lblReward=[[UILabel alloc]initWithFrame:pageFrame];
[lblReward setFrame:CGRectMake(i * (scrollView.bounds.size.width)+60, 200, 200, 25)];
lblReward.backgroundColor=[UIColor clearColor];
lblReward.textColor=[UIColor whiteColor];
[scrollView addSubview:lblReward];
NSString *strReward=[[pageControlData objectAtIndex:i]objectForKey:@"Reward"];
NSLog(@"strDetails=%@",strReward);
[lblReward setText:strReward];
[lblReward release];
UIButton *btnCheckButton=[[UIButton alloc]initWithFrame:pageFrame ];
[ btnCheckButton setFrame:CGRectMake(i * (scrollView.bounds.size.width)+250, 260, 20, 20)];
[btnCheckButton setImage:[UIImage imageNamed:@"NO.png"] forState:UIControlStateNormal];
[btnCheckButton addTarget:self action:@selector(checkBoxClicked:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:btnCheckButton];
[btnCheckButton release];
UIButton *backButton=[[UIButton alloc]initWithFrame:pageFrame ];
[ backButton setFrame:CGRectMake(i * (scrollView.bounds.size.width)+10, 410, 30, 30)];
[backButton setImage:[UIImage imageNamed:@"Arrow Icon.png"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:backButton];
[backButton release];
UIButton *showcaseButton=[[UIButton alloc]initWithFrame:pageFrame ];
[ showcaseButton setFrame:CGRectMake(i * (scrollView.bounds.size.width)+270, 410, 30, 30)];
[showcaseButton setImage:[UIImage imageNamed:@"Showcase Icon.png"] forState:UIControlStateNormal];
[showcaseButton addTarget:self action:@selector(showcaseButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:showcaseButton];
[showcaseButton release];
}
现在我想通过点击checkButton来显示标签。
答案 0 :(得分:2)
使用scrollview的contentOffset属性确定页面。例如:
NSInteger index = scrollView.contentOffset.x / scrollView.frame.size.width;
答案 1 :(得分:1)
您可以通过以下方式获取页面控制的当前页面: -
int currentPageNo=[*yourPageControlObjectName*.currentPage];
来自Apple Docs: -
currentPage
当前页面,由接收器显示为白点。
@property(nonatomic) NSInteger currentPage
讨论 属性值是一个整数,指定当前页面减去一;因此值为零(默认值)表示第一页。页面控件将当前页面显示为白点。超出可能范围的值固定为0或numberOfPages减1。