Created
September 10, 2011 13:58
-
-
Save kylehowells/1208338 to your computer and use it in GitHub Desktop.
Add Page to SpringBoard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static UIView *greenView = nil; | |
%hook SBIconScrollView | |
// Make it wider | |
-(void)setContentSize:(CGSize)size{ | |
if (!greenView) { | |
greenView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)] autorelease]; | |
greenView.backgroundColor = [UIColor greenColor]; | |
[self addSubview:greenView]; | |
} | |
CGSize newSize = CGSizeMake(size.width + greenView.bounds.size.width, size.height); | |
CGRect newFrame = greenView.frame; | |
newFrame.origin.x = size.width; | |
greenView.frame = newFrame; | |
%orig(newSize); | |
} | |
// Make the page control show the correct page | |
-(void)setContentOffset:(CGPoint)offset{ | |
%orig; | |
if (offset.x > (greenView.frame.origin.x-20) && greenView) { | |
SBIconController *iconController = (SBIconController*)[%c(SBIconController) sharedInstance]; | |
UIPageControl *pageControl = MSHookIvar<UIPageControl *>(iconController, "_pageControl"); | |
CGFloat pageWidth = self.frame.size.width; | |
int currentPage = floor((offset.x - pageWidth / 2) / pageWidth) + 1; | |
pageControl.currentPage = currentPage; | |
} | |
} | |
%end | |
%hook SBIconListPageControl | |
// Add a page to the page control | |
-(void)setNumberOfPages:(int)page{ | |
%orig(page+1); | |
} | |
%end | |
%hook SBIconController | |
// Fixes taping the page control & slide to the next page | |
-(void)pageControl:(UIPageControl*)control didRecieveTouchInDirection:(int)direction{ | |
UIPageControl *pageControl = MSHookIvar<UIPageControl *>(self, "_pageControl"); | |
if (direction == 1 && control.currentPage == (control.numberOfPages-2) && greenView) { | |
[self scrollRight]; | |
pageControl.currentPage++; | |
} | |
else if (direction == 0 && (pageControl.currentPage == pageControl.numberOfPages-1)) { | |
[(UIScrollView*)[self scrollView] setContentOffset:CGPointMake((greenView.frame.origin.x-greenView.frame.size.width), 0) animated:YES]; | |
pageControl.currentPage--; | |
} | |
else { | |
%orig; | |
} | |
} | |
// Fix the page control showing the right page | |
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ | |
%orig; | |
if (scrollView.contentOffset.x == greenView.frame.origin.x && scrollView && greenView) { | |
UIPageControl *pageControl = MSHookIvar<UIPageControl *>(self, "_pageControl"); | |
CGFloat pageWidth = scrollView.frame.size.width; | |
int currentPage = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; | |
pageControl.currentPage = currentPage; | |
} | |
} | |
// Fix the page control again | |
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ | |
%orig; | |
if (scrollView.contentOffset.x == greenView.frame.origin.x && scrollView && greenView) { | |
UIPageControl *pageControl = MSHookIvar<UIPageControl *>(self, "_pageControl"); | |
CGFloat pageWidth = scrollView.frame.size.width; | |
int currentPage = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1; | |
pageControl.currentPage = currentPage; | |
} | |
} | |
%end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment