zoukankan      html  css  js  c++  java
  • 自定义滚动控件(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
  • 相关阅读:
    ASP.NET在禁用视图状态的情况下仍然使用ViewState对象【转】
    Atcoder Regular Contest 061 D Card Game for Three(组合数学)
    Solution 「CERC 2016」「洛谷 P3684」机棚障碍
    Solution 「CF 599E」Sandy and Nuts
    Solution 「洛谷 P6021」洪水
    Solution 「ARC 058C」「AT 1975」Iroha and Haiku
    Solution 「POI 2011」「洛谷 P3527」METMeteors
    Solution 「CF 1023F」Mobile Phone Network
    Solution 「SP 6779」GSS7
    Solution 「LOCAL」大括号树
  • 原文地址:https://www.cnblogs.com/fusheng-it/p/5374209.html
Copyright © 2011-2022 走看看