Permalink
Browse files

Support auto resizing methods

Add intrinsicContentSize and fittingSize, to support auto resizing.
  • Loading branch information...
1 parent 62df7b1 commit 2c3c0d5fe90811f43eb2a3652f9bdf18b3a304a2 @slavikshen slavikshen committed Feb 26, 2013
Showing with 14 additions and 5 deletions.
  1. +12 −4 BFPageControl.m
  2. +2 −1 Example/Example/AppDelegate.m
View
@@ -129,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;
@@ -290,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
@@ -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)];
}
///////////////////////////////////////////////////////////////////////////////////////////////////

0 comments on commit 2c3c0d5

Please sign in to comment.