Window Location Hrefhref property returns the URL of the current page.
var lighboxHeight = (pagenumber-1)*window.
As an alternative way (not an all-in-one solution), WordPress has its own functions which you can utilize depending on a page that is currently being displayed. Let's take a look at the examples below. $current_url = home_url( '/' ); That's it, feel free to try!
There is no UIScrollView
property for the current page. You can calculate it with:
int page = scrollView.contentOffset.x / scrollView.frame.size.width;
If you want to round up or down to the nearest page, use:
CGFloat width = scrollView.frame.size.width;
NSInteger page = (scrollView.contentOffset.x + (0.5f * width)) / width;
I pretty recommend you to use this code
int indexOfPage = scrollView.contentOffset.x / scrollView.frame.size.width;
but if you use this code your view doesn't need to be exactly on the page that indexOfPage gives you. It because I also recommend you to use this code only in this method
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{}
which is called when your scrollView finishes scrolling and to have number of your page really sharp
I recommend you to set your scrollView to paged enabled with this code
[scrollView setPagingEnabled:YES];
So finally it should look like that way
-(void) methodWhereYouSetYourScrollView
{
//set scrollView
[scrollView setPagingEnabled:YES];
scrollView.delegate = self;
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
int indexOfPage = scrollView.contentOffset.x / scrollView.frame.size.width;
//your stuff with index
}
In swift I would do it in extension:
extension UIScrollView {
var currentPage:Int{
return Int((self.contentOffset.x+(0.5*self.frame.size.width))/self.frame.width)+1
}
}
Then just call:
scrollView.currentPage
As above but as a category
@interface UIScrollView (CurrentPage)
-(int) currentPage;
@end
@implementation UIScrollView (CurrentPage)
-(int) currentPage{
CGFloat pageWidth = self.frame.size.width;
return floor((self.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
}
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With