Created
March 24, 2010 15:22
-
-
Save karlforshaw/342387 to your computer and use it in GitHub Desktop.
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
var buttonBar = [self blankButtonBar]; //[buttonBar setBackgroundColor:[CPColor redColor]]; | |
var bounds = [_pageViewInner bounds]; | |
var answers = [aQuestion answers]; | |
// Add the buttons (answers) | |
var padding = 10; | |
var nextXPos = 0; | |
for (var i=0; i<answers.length; i++) { | |
var newButton = [[CPButton alloc] initWithFrame:CGRectMakeZero()]; | |
[newButton setTitle:[answers[i] title]]; | |
[newButton sizeToFit]; | |
[newButton setFrame:CGRectMake(nextXPos, 0, | |
CGRectGetWidth([newButton bounds]) + 20, | |
18 | |
)]; | |
[newButton setTarget:[self windowController]]; | |
newButton.nextQuestionID = [answers[i] nextQuestionID]; | |
newButton.wizardAnswerObject= answers[i]; | |
[newButton setAction:@selector(setNextQuestion:)]; | |
[buttonBar addSubview:newButton]; | |
nextXPos += CGRectGetWidth([newButton bounds]) + padding; | |
} | |
// Center the buttons | |
var buttonsWidth = nextXPos - padding; | |
var buttonsCenter = buttonsWidth / 2; | |
var pageInnerCenter = CGRectGetWidth([_pageViewInner bounds]) /2; | |
var toTheRight = pageInnerCenter - buttonsCenter; | |
if (answers.length == 1) { | |
var button = [buttonBar subviews][0]; | |
[button setFrameOrigin:CGPointMake( | |
pageInnerCenter - buttonsWidth, | |
0 | |
]; | |
} | |
else { | |
for (var j=0; j<[buttonBar subviews].length; j++) { | |
var button = [buttonBar subviews][j]; | |
[button setFrameOrigin:CGPointMake( | |
CGRectGetMinX([button frame]) + toTheRight, | |
0 | |
)]; | |
} | |
} | |
// Add whats there to the page | |
[_pageViewInner replaceSubview:_buttonBar with:buttonBar]; | |
_buttonBar = buttonBar; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment