pageControl指示器和图片放大-b

小编由于篇幅问题,截取了最后一篇,如果需要看其他的三篇文章,可以去笔者的简书看:http://www.jianshu.com/users/9f3739421d15/latest_articles

另外这个demo的github地址是:https://github.com/zhYes/YSBiggerPageContrl

Untitled3.gif


代码部分 :

  • 添加pageControl

- (void)addPageControl {    
    CGFloat pageW = 20 * _urls.count;    
    CGFloat pageH = kPageHeight;     
    _myPageControl = [[UIPageControl alloc] initWithFrame:CGRectMake((_header.hm_width - pageW) * 0.5, _header.hm_height - pageH, pageW, pageH)];//    
    _myPageControl.backgroundColor = [UIColor redColor];     
    [_header addSubview:_myPageControl];     
    _myPageControl.pageIndicatorTintColor = [UIColor greenColor];     
    _myPageControl.currentPageIndicatorTintColor = [UIColor redColor];     
    _myPageControl.numberOfPages = _urls  .count;
  • 释义 : 常规代码.. 这里可以 设置当前选中的指示颜色以及默认颜色

  • 跟随滚动偏移

4EA86B1A-D55B-4756-B220-9DA701BEF35B.png

释义 : 随父控件_header滚动 并渐变消失即可
注意 : _header并非加到tableView的headerView上 !!

-
-

对于个性的你一定觉得小圆点点low爆了对不对 ?

完善后的效果图 二 :

Untitled1.gif

代码实现 :

QQ20160908-0.png

[_myPageControl setValue:[UIImage imageNamed:@"pageCurrent.png"] forKey:@"_currentPageImage"];    [_myPageControl setValue:[UIImage imageNamed:@"pageOther.png"] forKey:@"_pageImage"];

释义 : pageControl在iOS8.4以后有一些属性变为私有,苹果并没有暴露给我们,但是我们依然可以通过kvc来替换使用自定义的image

  • 探究证明

- (void)getUIPageControlProperties{    
    unsigned int count;    
/**      
1.获取属性列表y      
参数1:获取哪个类的      
参数2:count表示你该类里面有多少个属性       
propertyList 它就相当于一个数组      
*/     
/**      
class_copyPropertyList 这个方法只能获取类的公有属性       
class_copyIvarList 能获取类的所有属性,包括私有属性      
*/      
    Ivar *propertyList = class_copyIvarList([UIPageControl class], &count);    
    for (int i=0; i<count; i++) {        //2.取出objc_property_t数组中的property         
        Ivar property = propertyList[i];        //3.获取的是C语言的名称         
        const char *cPropertyName = ivar_getName(property);        //4.将C语言的字符串转成OC的         
        NSString * ocPropertyName = [[NSString alloc] initWithCString:cPropertyName encoding:NSUTF8StringEncoding];        //5.打印结果如下 ,我们重点关心的就是 _pageImage , _currentPageImage         
        //  我们知道了这两个名字 就可以利用KVC设置我们想要的图片!//        NSLog(@"%@",ocPropertyName);         
        /*           
        2016-09-08 10:57:36.488 轮播图two[71257:3736607] _lastUserInterfaceIdiom          
        2016-09-08 10:57:36.489 轮播图two[71257:3736607] _indicators          
        2016-09-08 10:57:36.489 轮播图two[71257:3736607] _currentPage          
        2016-09-08 10:57:36.490 轮播图two[71257:3736607] _displayedPage          
        2016-09-08 10:57:36.490 轮播图two[71257:3736607] _pageControlFlags          
        2016-09-08 10:57:36.493 轮播图two[71257:3736607] _currentPageImage          
        2016-09-08 10:57:36.494 轮播图two[71257:3736607] _pageImage          
        2016-09-08 10:57:36.494 轮播图two[71257:3736607] _currentPageImages          
        2016-09-08 10:57:36.495 轮播图two[71257:3736607] _pageImages          
        2016-09-08 10:57:36.495 轮播图two[71257:3736607] _backgroundVisualEffectView          
        2016-09-08 10:57:36.496 轮播图two[71257:3736607] _currentPageIndicatorTintColor          
        2016-09-08 10:57:36.496 轮播图two[71257:3736607] _pageIndicatorTintColor          
        2016-09-08 10:57:36.496 轮播图two[71257:3736607] _legibilitySettings          
        2016-09-08 10:57:36.497 轮播图two[71257:3736607] _numberOfPages          
        */     
    }    
    //5.C语言中,用完copy,create的东西之后,最好释放     
    free(propertyList);
}

释义 运用runtime获取Ivar全部属性,打印可得~~
我们重点关心的就是 _pageImage , _currentPageImage // 我们知道了这两个名字 就可以利用KVC设置我们想要的图片!

原文地址:https://www.cnblogs.com/isItOk/p/5866852.html