UIPageControl 常用方法

- (void)viewDidLoad

{

    [superviewDidLoad];

    self.view.backgroundColor = [UIColorcolorWithPatternImage:[UIImageimageNamed:@"bg_blank.png"]];

  //  self.view.backgroundColor = [UIColor clearColor];

 

//定义UIScrollView

    scrollview = [[UIScrollViewalloc] init];

    scrollview.frame = CGRectMake(10, 0, 300, 108);    

    scrollview.contentSize = CGSizeMake(600, 108);  //scrollview的滚动范围

    scrollview.showsVerticalScrollIndicator = NO;

    scrollview.showsHorizontalScrollIndicator = NO;

//myScrollView.clipsToBounds = YES;

    scrollview.delegate = self;

     scrollview.scrollEnabled = YES;

    scrollview.pagingEnabled = YES; //使用翻页属性 

    scrollview.bounces = NO; 

      

//定义WebView加载曲线图

    webview = [[UIWebViewalloc] init];

    webview.frame = CGRectMake(-7, -10, 307, 118);

    webview.delegate = self;

    [webviewsetBackgroundColor:[UIColorclearColor]];

    [webviewsetOpaque:NO];    

    NSString *fullPath = [NSBundlepathForResource:@"sline"ofType:@"htm"inDirectory:[[NSBundlemainBundle] bundlePath]];  

    [self.webviewloadRequest:[NSURLRequestrequestWithURL:[NSURLfileURLWithPath:fullPath]]];   

    

    //用来制定边框

    view22 = [[UIViewalloc] init];

    //将图层的边框设置为圆脚   

    view22.layer.cornerRadius = 10;

    view22.layer.masksToBounds = YES;

    //给图层添加一个有色边框

    view22.layer.borderWidth = 1;

    //view1.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor]; 

    view22.layer.borderColor = [[UIColorcolorWithRed:0green:0blue:0alpha:1] CGColor];   

    view22.frame = CGRectMake(0, 0, 300, 108);

    view22.backgroundColor = [UIColorcolorWithRed:0.31green:0.31blue:0.31alpha:1];  

 

    tableview.frame = CGRectMake(0, 21, 300, 87);

    tableview.allowsSelection = NO;

    tableview.backgroundColor = [UIColorcolorWithRed:0.31green:0.31blue:0.31alpha:1];

 

//用来制定边框

    view11 = [[UIViewalloc] init];

    //将图层的边框设置为圆脚   

    view11.layer.cornerRadius = 10;

    view11.layer.masksToBounds = YES;

    //给图层添加一个有色边框

    view11.layer.borderWidth = 1;

    //view1.layer.borderColor = [[UIColor colorWithRed:0.52 green:0.09 blue:0.07 alpha:1] CGColor]; 

    view11.layer.borderColor = [[UIColorcolorWithRed:0green:0blue:0alpha:1] CGColor];   

    view11.frame = CGRectMake(300, 0, 300, 108);

    view11.backgroundColor = [UIColorblackColor];

 

    [view11addSubview:tableview];

    [scrollviewaddSubview:view11];

   

    [view22addSubview:webview];

    [scrollviewaddSubview:view22];

 

//定义PageControll

    pageControl = [[UIPageControlalloc] init];

    pageControl.frame = CGRectMake(150, 100, 20, 20);//指定位置大小

    pageControl.numberOfPages = 2;//指定页面个数

    pageControl.currentPage = 0;//指定pagecontroll的值,默认选中的小白点(第一个)

    [pageControladdTarget:selfaction:@selector(changePage:)forControlEvents:UIControlEventValueChanged];

    //添加委托方法,当点击小白点就执行此方法

    [self.viewaddSubview:scrollview];

    [self.viewaddSubview:pageControl];    

}

 

//scrollview的委托方法,当滚动时执行

- (void)scrollViewDidScroll:(UIScrollView *)sender {

    int page = scrollview.contentOffset.x / 290;//通过滚动的偏移量来判断目前页面所对应的小白点

     pageControl.currentPage = page;//pagecontroll响应值的变化

}

 

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {

  

}

 

//pagecontroll的委托方法

- (IBAction)changePage:(id)sender { 

    int page = pageControl.currentPage;//获取当前pagecontroll的值

    [scrollview setContentOffset:CGPointMake(300 * page, 0)];//根据pagecontroll的值来改变scrollview的滚动位置,以此切换到指定的页面

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值