Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for IB #1

Merged
merged 3 commits into from
Feb 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
Example/.DS_Store
.DS_Store
# Mac OS X
*.DS_Store

# Xcode
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
*.xcuserstate
project.xcworkspace/
xcuserdata/

# Generated files
*.o
*.pyc


#Python modules
MANIFEST
dist/
build/

# Backup files
*~.nib
*.swp
2 changes: 1 addition & 1 deletion BFPageControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@
/// @name Misc Properties
///---------------------------------------------------------------------------------------

@property (nonatomic, assign)id <BFPageControlDelegate>delegate;
@property (nonatomic, assign) IBOutlet id <BFPageControlDelegate>delegate;

@end
36 changes: 25 additions & 11 deletions BFPageControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ @implementation BFPageControl

-(id)initWithFrame: (NSRect)frameRect
{
if(self = [super initWithFrame: NSMakeRect(frameRect.origin.x, frameRect.origin.y, 0, 0)])
if(self = [super initWithFrame:frameRect])
{
_numberOfPages = 0;
_indicatorDiameterSize = 10.0;
Expand All @@ -104,11 +104,21 @@ -(void)updateCurrentPageDisplay
if(_matrix)
[_matrix removeFromSuperview], _matrix = nil;

if(_hidesForSinglePage && self.numberOfPages < 2)
NSUInteger numberOfPages = self.numberOfPages;
if(_hidesForSinglePage && numberOfPages < 2)
return;

NSSize size = [self sizeForNumberOfPages: _numberOfPages];
NSRect frame = NSMakeRect(0, 0, size.width, size.height);

CGRect bounds = self.bounds;
CGFloat W = bounds.size.width;
CGFloat H = bounds.size.height;

CGFloat x = floorf((W-size.width)/2);
CGFloat y = floorf((H-size.height)/2);

NSRect frame = NSMakeRect(x, y, size.width, size.height);

_matrix = [[NSMatrix alloc] initWithFrame: frame mode: NSRadioModeMatrix cellClass: [BFPageControlCell class] numberOfRows: 1 numberOfColumns: _numberOfPages];
_matrix.drawsBackground = YES;
_matrix.backgroundColor = [NSColor clearColor];
Expand All @@ -119,10 +129,6 @@ -(void)updateCurrentPageDisplay
[_matrix setAction: @selector(_clickedItem:)];
[self addSubview: _matrix];

frame.origin.y = self.frame.origin.y;
frame.origin.x = self.frame.origin.x;
super.frame = frame;

__weak id wSelf = self;
void(^block)(NSRect, NSView *, BOOL, BOOL) = ^(NSRect frame, NSView *theView, BOOL isSelected, BOOL isHighlighted){
BFPageControl *aSelf = wSelf;
Expand Down Expand Up @@ -185,19 +191,15 @@ -(void)setCurrentPage:(NSInteger)currentPage

-(void)setFrame: (NSRect)frameRect
{
frameRect.size = [self sizeForNumberOfPages: _numberOfPages];
[super setFrame: frameRect];

[self updateCurrentPageDisplay];
}

///////////////////////////////////////////////////////////////////////////////////////////////////

-(void)setBounds: (NSRect)aRect
{
aRect.size = [self sizeForNumberOfPages: _numberOfPages];
[super setBounds: aRect];

[self updateCurrentPageDisplay];
}

Expand Down Expand Up @@ -284,4 +286,16 @@ -(void)setDrawingBlock: (void (^)(NSRect frame, NSView *inView, BOOL isSelected,
[self updateCurrentPageDisplay];
}

//! size to fit the current setting
- (NSSize)intrinsicContentSize {

NSSize size = _matrix.frame.size;
return size;

}

- (NSSize)fittingSize {
return [self intrinsicContentSize];
}

@end
3 changes: 2 additions & 1 deletion Example/Example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ -(void)applicationDidFinishLaunching:(NSNotification *)aNotification
[[NSBezierPath bezierPathWithOvalInRect: frame] stroke];
}];
[self.window.contentView addSubview: control];
[control setFrame: CGRectMake(frame.size.width / 2 - control.frame.size.width / 2, 50, 40, 40)];
CGSize size = [control intrinsicContentSize];
[control setFrame: CGRectMake((frame.size.width - size.width)/2, 50, size.width, size.height)];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down