• 类似新闻客户端.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


  • 相关阅读:
    Spring中的AOP实现思路
    手写IOC-SPRINGPMVC-CONNPOOL
    职责链模式
    判断一个二叉树是不是对称二叉树
    合并区间
    shell命令中用source 和sh(或者bash)执行脚本的区别,以及export的作用
    angular指令的compile,prelink 和 postlink以及controller
    angular的启动原理
    高并发优化方法
    搭建ssm框架的一个小坑
  • 原文地址:https://www.cnblogs.com/xukunhenwuliao/p/3576226.html
Copyright © 2020-2023  润新知