1
這是我的UIScrollView
功能,我在一頁中顯示了7張圖片中的7張。它的工作原理,但我想顯示和更改UIPageControl
。如何在UIScrollView中添加UIPageControl
- (void)layoutScrollImages{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}
- (void)viewDidLoad {
kScrollObjHeight = 172.0;
kScrollObjWidth = 146.0;
kNumImages = 39;
scrollView1=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 596, 1022, 172)];
scrollView1.showsVerticalScrollIndicator=YES;
scrollView1.userInteractionEnabled=YES;
[self.view addSubview:scrollView1];
self.view.backgroundColor = [UIColor whiteColor];
[scrollView1 setBackgroundColor:[UIColor whiteColor]];
[scrollView1 setCanCancelContentTouches:NO];
scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView1.clipsToBounds = NO;
scrollView1.scrollEnabled = YES;
scrollView1.pagingEnabled = YES;
NSUInteger j;
for (j = 1; j <= kNumImages; j++)
{
NSString *imageName = [NSString stringWithFormat:@"thumb_%lu.png",(unsigned long)j];
image = [UIImage imageNamed:imageName];
imageView = [[UIImageView alloc] initWithImage:image];
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = j; // tag our images for later use when we place them in serial fashion
[scrollView1 addSubview:imageView];
}
pageCtrl = [[UIPageControl alloc] init];
pageCtrl.frame = CGRectMake(-130, CGRectGetMidY(self.view.bounds)+25, 1024, 100);
[pageCtrl setNumberOfPages:5];
pageCtrl.currentPage = 0;
pageCtrl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageCtrl.currentPageIndicatorTintColor = [UIColor blackColor];
[self.view addSubview:pageCtrl];
}
如何在這裏使用UIPageControl?
我怎麼能滾動滾動視圖 – user3069029
是的,可以在滾動視圖的委託方法來實現,當改變網頁控制 – Venkat
你能不能告訴我的一些腳本滾動視圖委託 – user3069029