自定义滚动控件(Pagecontrol)

//
//  MyPageCorol.h
//  lejiahui
//
//  Created by iOS开发 on 16/4/10.
//  Copyright © 2016年 zhongmingwuye. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MyPageCorol : UIView

/**  当前页数 */
@property(nonatomic,assign) NSInteger  correntPage;

/** itmenSize */
@property(nonatomic,assign) CGSize itmeSize;

+ (MyPageCorol *)myPageControlWithSuperView:(UIView *)superView;

- (void)setImage:(UIImage *)image andSelectImage:(UIImage *)slectImage totalNum:(NSInteger)totalNum;

- (void)setColor:(UIColor *)color andSelectColor:(UIColor*)selectColor totalNum:(NSInteger)totalNum;

@end

//
//  MyPageCorol.m
//  lejiahui
//
//  Created by iOS开发 on 16/4/10.
//  Copyright © 2016年 zhongmingwuye. All rights reserved.
//

#import "MyPageCorol.h"

@interface MyPageCorol()
{
    NSMutableArray * _pageItems;
    UIColor * _selectedColor;
    UIColor * _color;
    
    UIImage * _image;
    UIImage * _selectedImage;
    
    BOOL _isImage;
    
    NSInteger _width;
    NSInteger _height;
}

@end

@implementation MyPageCorol

+ (MyPageCorol *)myPageControlWithSuperView:(UIView *)superView{
    MyPageCorol * pl = [[MyPageCorol alloc]init];
    pl.frame = CGRectMake(0, superView.frame.size.height-20, superView.frame.size.width, 20);
    pl.backgroundColor = [UIColor clearColor];
    [superView addSubview:pl];
    return pl;
}

- (instancetype)init{
    if (self=[super init]) {
        self.itmeSize = CGSizeMake(0, 0);
    }
    return self;
}

- (void)setItmeSize:(CGSize)itmeSize{
    _itmeSize = itmeSize;
    _width = itmeSize.width;
    _height = itmeSize.height;
}
//设置图片形式
- (void)setImage:(UIImage *)image andSelectImage:(UIImage *)slectImage totalNum:(NSInteger)totalNum{
    _isImage = YES;
    _image = image;
    _selectedImage = slectImage;
    
    _pageItems = [[NSMutableArray alloc]init];
    NSInteger num = totalNum;
    
    NSInteger height = 10;
    NSInteger width  =20;
    if (self.itmeSize.height!=0&&self.itmeSize.width!=0) {
        height = self.itmeSize.height;
        width = self.itmeSize.width;
    }
    NSInteger sepreate = 5;
    NSInteger totalWidth = num*width+(num-1)*sepreate;
    NSInteger orangex = (self.frame.size.width-totalWidth)/2;
    NSInteger orangey = (self.frame.size.height - height)/2;
    for (int i = 0;i< num; i++) {
        UIImageView * pageView = [[UIImageView alloc]init];
        pageView.frame = CGRectMake(orangex+i*(width+sepreate), orangey, width, height);
        [_pageItems addObject:pageView];
        [self addSubview:pageView];
    }
    self.correntPage = 0;
}

//设置颜色形式
- (void)setColor:(UIColor *)color andSelectColor:(UIColor*)selectColor totalNum:(NSInteger)totalNum{
    _pageItems = [[NSMutableArray alloc]init];
    _color = color;
    _selectedColor = selectColor;

    NSInteger num = totalNum;
    NSInteger height = 5;
    NSInteger width  =20;
    if (self.itmeSize.height!=0&&self.itmeSize.width!=0) {
        height = self.itmeSize.height;
        width = self.itmeSize.width;
    }
    NSInteger sepreate = 5;
    NSInteger totalWidth = num*width+(num-1)*sepreate;
    NSInteger orangex = (self.frame.size.width-totalWidth)/2;
    NSInteger orangey = (self.frame.size.height - height)/2;
    for (int i = 0;i< num; i++) {
        UIView * pageView = [[UIView alloc]init];
        pageView.frame = CGRectMake(orangex+i*(width+sepreate), orangey, width, height);
        [_pageItems addObject:pageView];
        [self addSubview:pageView];
    }
    self.correntPage = 0;
}

- (void)setCorrentPage:(NSInteger)correntPage{
    _correntPage = correntPage;
    for (int i = 0; i<_pageItems.count; i++) {
        if (_isImage) {
            UIImageView * imageView= _pageItems[i];
            imageView.image = _image;
            if (correntPage==i) {
                imageView.image = _selectedImage;
            }
        }else{
            UIView * view = _pageItems[i];
            view.backgroundColor = _color;
            if (correntPage==i) {
                view.backgroundColor = _selectedColor;
            }
        }
    }
}

@end

 

转载于:https://www.cnblogs.com/fusheng-it/p/5374209.html

本Demo使用UICollectionView实现自动无限轮播功能。 主要功能: 1.实现自动轮播,可修改轮播的时间 2.轮播图片可以来自本地,也可来自网络,通过单独的方法进行设置即可。对于加载网络图片时,Demo中使用了YYWebImage,也可自行替换成SDWebImage。 3.重写了和系统UIPageControl一样的功能,可用图片代替PageControl上的点点,也可自定义其颜色以及切换动画。 使用方法:使用方法比较简单。 /** * 加载本地图片Banner */ - (void)setupLocalBannerImageView { NSArray *array = @[@"1.png", @"2.png", @"3.png", @"4.png", @"5.png"]; FFBannerView *bannerVew = [FFBannerView bannerViewWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 200) locationImageArray:array]; bannerVew.timeInterval = 2.0; [self.view addSubview:bannerVew]; } /** * 加载网络图片Banner */ - (void)setupNetWorkBannerImageView { NSArray *array = @[@"http://i3.download.fd.pchome.net/t_960x600/g1/M00/07/09/oYYBAFMv8q2IQHunACi90oB0OHIAABbUQAAXO4AKL3q706.jpg", @"http://images.weiphone.net/attachments/photo/Day_120308/118871_91f6133116504086ed1b82e0eb951.jpg", @"http://benyouhuifile.it168.com/forum/macos/attachments/month_1104/110425215921926a173e0f728e.jpg", @"http://benyouhuifile.it168.com/forum/macos/attachments/month_1104/1104241737046031b3a754f783.jpg"]; FFBannerView *bannerVew = [FFBannerView bannerViewWithFrame:CGRectMake(0, 250, [UIScreen mainScreen].bounds.size.width, 200) netWorkImageArray:array placeHolderImage:nil]; bannerVew.timeInterval = 2.0; bannerVew.pageControlStyle = FFPageControlStyleMiddle; bannerVew.delegate = self; [self.view addSubview:bannerVew]; } 以上方式即可简单使用,如需自定义PageControl也可继承FFAbstractDotView,做些基本的设置即可。 gitHub下载地址:喜欢的朋友请给个星呗! 欢迎各位一起来讨论,有问题请发邮箱270452746@qq.com或者直接加我QQ:270452746进行讨论。谢谢!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值