Thousand Squared

Customize your PageControl just like ViewPagerIndicator

| Comments

最近開始接觸 Android 發現有好多人寫好的 libary 可以用,就像 ViewPagerIndicator,因此也想再 iOS 上弄一個一樣的 indicator,雖然這很不像是 iOS 的 design pattern,但是身為一個 hacker 就是要來嘗試一下呀!

View source on Github

利用 SMPageControl

要怎麼做?很簡單,利用 SMPageControl

SMPageControl 提供了很多 customize 選項,就利用這些選項把圓形的 page dot 變成 方形或任意形狀啦。

主要 custom 的程式碼如下

UIImage* currentPageIndicatorImage = [UIImage imageWithRect:CGRectMake(0, 0, indicatorWith, VIEWS_PAGE_CONTROL_HEIGHT)
                                                          color:[UIColor hexARGB:0xFFFF6666]];

    UIImage* pageIndicatorImage = [UIImage imageWithRect:CGRectMake(0, 0, indicatorWith, VIEWS_PAGE_CONTROL_HEIGHT)
                                                   color:[UIColor hexARGB:0xFF333333]];

    [self.pageControl setCurrentPageIndicatorImage:currentPageIndicatorImage];
    [self.pageControl setPageIndicatorImage:pageIndicatorImage];

先用程式建立方形的 UIImage,再設定為 pageIndicator image,就可以得到方形的 pageControl啦。

View source on Github

Comments

comments powered by Disqus