UIScrollView 分页

UIScrollView 分页


#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    CGFloat w=self.scrollView.frame.size.width;
    CGFloat h=self.scrollView.frame.size.height;
    int count=5;
    
    for(int i=0;i (int)(0.3 + 0.5) > 0
    // 0.6 > (int)(0.6 + 0.5) > 1
    // 小数四舍五入为整数 : (int)(小数 + 0.5)
    int page = (int)(scrollView.contentOffset.x / scrollView.frame.size.width + 0.5);    self.pageControl.currentPage=page;
}

@end



你可能感兴趣的:(UIScrollView 分页)