• 类似新闻客户端.UIPageControl和UIScroll的结合使用,滑点控制图片页码.显示图片页码


    //设置协议.
    @interface RootViewController : UIViewController<UIScrollViewDelegate>
    //声明两个公用属性,也可以使用延展
    @property (nonatomic,retain)UIScrollView * aScrollView;
    @property (nonatomic,retain)UIPageControl * aPageControl;
    @end
    //以下为.m文件
    #import "RootViewController.h"
    
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.view.backgroundColor=[UIColor clearColor];
           self.aPageControl=[[UIPageControl alloc] initWithFrame:CGRectMake(80, 320, 150, 30)];
            _aPageControl.numberOfPages=5;
            _aPageControl.currentPage=0;
            _aPageControl.backgroundColor=[UIColor clearColor];
            _aPageControl.currentPageIndicatorTintColor=[UIColor redColor];
            _aPageControl.pageIndicatorTintColor=[UIColor blueColor];
           [self.view addSubview:_aPageControl];
           [_aPageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
        
        //添加scroll
        self.aScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 320, 240)];
        _aScrollView.backgroundColor=[UIColor greenColor];
        //_aScrollView.bounces=YES;
        _aScrollView.userInteractionEnabled=YES;
        _aScrollView.pagingEnabled=YES;
        _aScrollView.scrollEnabled=YES;
        _aScrollView.contentSize=CGSizeMake(320*5, 240);
        _aScrollView.bounces=NO;
        [self.view addSubview:_aScrollView];
        
        NSMutableArray *array=[[NSMutableArray alloc] init];
        for (int i=0; i<5; i++) {
            [array addObject:[NSString stringWithFormat:@"test-%d(被拖移).tiff",i+1]];
        }
        for (int i=0; i<5; i++) {
            UIImageView *imageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:array[i]]];
            imageView.frame=CGRectMake(320*i, 0, 320, 240);
            [_aScrollView addSubview:imageView];
        }
        _aScrollView.delegate=self;
        
        
    }
    - (void)changePage:(UIPageControl *)aPage
    
    {
        _aScrollView.contentOffset=CGPointMake(_aPageControl.currentPage*320, 0);
    }
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
      _aPageControl.currentPage=_aScrollView.contentOffset.x/320;
    }
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    @end


  • 相关阅读:
    Java中的Math类、Array类、大数据运算
    关于VUE3 setup()中动态获取dom
    iframe内部修改iframe src链接
    vue Router4动态添加路由
    时间戳
    vue watch 中的this问题
    el-date-picker 设置事件格式为时间戳
    TP6 阿帕奇去 index.php
    dbeaver 驱动下载失败
    dbeaver mysql8+ 出现 The server time zone value '�й���׼ʱ��' ...错误
  • 原文地址:https://www.cnblogs.com/xukunhenwuliao/p/3576226.html
Copyright © 2020-2023  润新知