내 앱에서 간단한 슬라이드 쇼보기를 만들고 있습니다. 내 UIPageControl을 UIScrollView에 연결하고 싶습니다. 너무 어렵지는 않지만 어디서나 간단한 솔루션을 찾을 수 없었습니다. 아래는 제 코드입니다.프로그래밍 방식으로 UIPageControl을 UIScrollView에 연결하기
HelpViewController.h
#import <UIKit/UIKit.h>
@interface HelpViewController : UIViewController{
}
@end
#import "HelpViewController.h"
@interface HelpViewController()
@end
@implementation HelpViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect scrollViewFrame = CGRectMake(0, 62, 320, 404);
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
[self.view addSubview:scrollView];
CGSize scrollViewContentSize = CGSizeMake(640, 404);
[scrollView setContentSize:scrollViewContentSize];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(200, 200, 50, 21)];
[label setText:@"Hello"];
[scrollView addSubview:label];
[scrollView setPagingEnabled:YES];
scrollView.showsHorizontalScrollIndicator = NO;
UIPageControl *pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(110,5,100,100);
pageControl.numberOfPages = 2;
pageControl.currentPage = 0;
[self.view addSubview:pageControl];
pageControl.backgroundColor = [UIColor redColor];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
정확하게 답변했습니다. https://stackoverflow.com/questions/3533047/how-do-you-combine-uiscrollview-with-uipagecontrol-to-show-different-views/14230698#14230698 답변이 더 좋습니다. 한 곳 ... 제안 된 변경 사항을 수정했습니다. – Renetik