改變UIPageControl圓點(diǎn)間距

方法一:使用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;
}

注意:這種方法因?yàn)檎{(diào)用私有API過不了app store 審核。

方法二:使用遍歷控件的所有子視圖,重設(shè)所有子視圖的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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,318評論 4 61
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,039評論 25 709
  • 秋風(fēng)颯颯凋梧葉,驚烏繞樹啼三匝。銀漢正低垂,星依銀漢飛,舊愁知幾許,短發(fā)愁千縷,吹笛不堪聞,月明江上村。 發(fā)現(xiàn)這首...
    愛看書不愛打瞌睡閱讀 395評論 0 0
  • 自從PMP通過后,有意將工作中一些事情當(dāng)作項(xiàng)目去管理,以此來增加更多一線實(shí)踐經(jīng)驗(yàn)。 前兩個月接到移動端頁面策劃工作...
    謝謝_Aza閱讀 881評論 0 0

友情鏈接更多精彩內(nèi)容