展示图

Posted pengyuan_D

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了展示图相关的知识,希望对你有一定的参考价值。

ViewController.h

@interface ViewController : UIViewController<UIScrollViewDelegate>

    UIPageControl *_pageCtrl;
    UIScrollView *_scrollView;

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad

    [super viewDidLoad];

//    NSMutableArray *imgArrary = [[NSMutableArray alloc] init];
    
    //创建滚动视图
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 300)];
    //隐藏滚动条
    _scrollView.showsHorizontalScrollIndicator = NO;
    
    //设置代理方法
    _scrollView.delegate = self;
    
    //分页效果
    _scrollView.pagingEnabled = YES;
    //设置内容尺寸
    _scrollView.contentSize = CGSizeMake(320*5, 300);
    [self.view addSubview:_scrollView];
    
    for(int i=1; i<6; i++) 
    
        NSString *name = [NSString stringWithFormat:@"image%d.jpg",i];
        UIImage *image = [UIImage imageNamed:name];
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        imageView.frame = CGRectMake(320*(i-1), 0, 320, 300);
        [_scrollView addSubview:imageView];
    
    
    //创建分页控键
    _pageCtrl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 300, 320, 20)];
    _pageCtrl.numberOfPages = 5;
    _pageCtrl.currentPage = 0;
    [_pageCtrl addTarget:self action:@selector(pageAction) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_pageCtrl];
    


#pragma mark - UIScrollView delegate
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
//
//    /*
//     0:  0--320 /320  0
//     1;   320--640  /320  1
//     */
//    
//    int count = scrollView.contentOffset.x/320;
//    _pageCtrl.currentPage = count;
//    
//

//视图停止以后调用
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
    int count = scrollView.contentOffset.x/320;
    _pageCtrl.currentPage = count;


- (void)pageAction 

    int index = _pageCtrl.currentPage;
    
    CGPoint point = CGPointMake(320*index, 0);
    
    
//    _scrollView.contentOffset = point;
    [_scrollView setContentOffset:point animated:YES];
    


@end


以上是关于展示图的主要内容,如果未能解决你的问题,请参考以下文章

Upload组件上传限制(宽、高、尺寸、格式)

图例中的分级尺寸符号

淘宝 ecshop 图片大小设置 问题

图片在浏览器窗口水平居中展示(图片尺寸不限制)

Magento 试图在产品展示和类别页面上根据“尺寸属性”显示产品价格范围?

小程序轮播图样式