ynamao ynamao - 1 year ago 125
iOS Question

change page Indicator Image [SMPageControl] / EAIntroView in swift

I'm trying to change the indicator image , following the example in EAIntroView

here is the objective-c code from EAIntroView

SMPageControl *pageControl = [[SMPageControl alloc] init];
pageControl.pageIndicatorImage = [UIImage imageNamed:@"pageDot"];
pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"selectedPageDot"];
[pageControl sizeToFit];
intro.pageControl = (UIPageControl *)pageControl;
intro.pageControlY = 130.f;

and here is the swift code I'm trying to implement

// SMPageControl
pageControl = SMPageControl()
pageControl.pageIndicatorImage = UIImage(named: "pageDot")
pageControl.currentPageIndicatorImage = UIImage(named: "selectedPageDot")
pageControl.backgroundColor = UIColor.clearColor()

intro.pageControl = pageControl as? UIPageControl

swift code has a warning here

intro.pageControl = pageControl as? UIPageControl

the warning is :

Cast from 'SMPageControl!' to unrelated type 'UIPageControl' always fails

any help ?

Answer Source

You can see from the source code of SMPageControl that it isn't a subclass of UIPageControl. Which means the error is expected: UIPageControl is a completely unrelated type, to which the value cannot be cast.

The Objective-C you pointed to might work, but it's bad and wrong: inline cast to UIPageControl achieves nothing here and can cause internal inconsistencies.

This is exactly the kind of sloppiness that Swift compiler is designed to prevent, and it's doing its job well.

Your best bet is to forgo using this library in Swift code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download