jverkoey/nimbus — Issue #153: Allow NILauncherView from xib or storyboard
Author: onomated
Created: 2012-02-03 14:42:02+00:00
State: open

Fantastic project guys. Using the NILauncherView as one of the views in a view controller i.e. not using NILauncherViewController.
I had to add implement -(id)initWithCoder:(NSCoder *) to design in storyboard. Here are my mods below:

```objective-c
///////////////////////////////////////////////////////////////////////////////////////////////////
-(void) _initialize
{
_maxNumberOfButtonsPerPage = NSIntegerMax;
_padding = UIEdgeInsetsMake(kDefaultPadding, kDefaultPadding,
kDefaultPadding, kDefaultPadding);

// The paging scroll view.
_scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
_scrollView.delegate = self;
_scrollView.pagingEnabled = YES;

// We don't need scroll indicators because we have a pager. Vertical scrolling is handled
// by each page's scroll view.
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.showsHorizontalScrollIndicator = NO;

[self addSubview:_scrollView];

// The pager displayed at the bottom of the scroll view.
_pager = [[UIPageControl alloc] init];
_pager.hidesForSinglePage = YES;

// So, this is weird. Apparently if you don't set a background color on the pager control
// then taps won't be handled anywhere but within the dot area. If you do set a background
// color, however, then taps outside of the dot area DO change the selected page.
// \(o.o)/
_pager.backgroundColor = [UIColor blackColor];
// Similarly for the scroll view anywhere there isn't a subview.
_scrollView.backgroundColor = [UIColor blackColor];
// We update these background colors when the launcher view's own background color is set.

// Don't update the pager when the user taps until we've handled the tap ourselves.
// This allows us to reset the page index forcefully if necessary without flickering the
// pager's current selection.
_pager.defersCurrentPageDisplay = YES;

// When the user taps the pager control it fires a UIControlEventValueChanged notification.
[_pager addTarget: self
action: @selector(pageChanged:)
forControlEvents: UIControlEventValueChanged];

[self addSubview:_pager];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
[self _initialize];
}
return self;
}

-(id) initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
[self _initialize];
}
return self;
}
```