改变UIPageControl圆点间距

方法一:使用runtime,替换控件私有方法

#import <objc/runtime.h>
+ (void)load
{
    Method origin = class_getInstanceMethod([self class], @selector(_indicatorSpacing));
    Method custom = class_getInstanceMethod([self class], @selector(custom_indicatorSpacing));
    method_exchangeImplementations(origin, custom);
}
- (double)custom_indicatorSpacing
{
    return 6.0;
}

注意:这种方法因为调用私有API过不了app store 审核。

方法二:使用遍历控件的所有子视图,重设所有子视图的frame

- (void)setCurrentPage:(NSInteger)page {
    NSUInteger magrin = 5;
    NSUInteger count = [self.subviews count];
    NSUInteger firstX = 0;
    CGSize size;
    size.height = 5;
    size.width = 5;
    firstX = (self.frame.size.width-size.width*count-magrin*(count-1))/2;
    
    for (NSUInteger i = 0; i < count; i++) {
        UIImageView* subview = [self.subviews objectAtIndex:i];
        [subview setFrame:CGRectMake(firstX+(size.width + magrin)*i, subview.frame.origin.y, size.width,size.height)];
    }
}

参考:
http://www.cnblogs.com/chyl411/p/5421668.html
https://zhidao.baidu.com/question/563396477476563524.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,246评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,441评论 25 708
  • 秋风飒飒凋梧叶,惊乌绕树啼三匝。银汉正低垂,星依银汉飞,旧愁知几许,短发愁千缕,吹笛不堪闻,月明江上村。 发现这首...
    爱看书不爱打瞌睡阅读 338评论 0 0
  • 自从PMP通过后,有意将工作中一些事情当作项目去管理,以此来增加更多一线实践经验。 前两个月接到移动端页面策划工作...
    谢谢_Aza阅读 796评论 0 0