Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my solution, i hope it helps. </p> <p>First define this struct somewhere:</p> <pre><code>typedef struct { int cols; }RowInfo; </code></pre> <p>Then:</p> <pre><code>-(void)layoutMenu:(CCMenu *)menu rowInfo:(RowInfo[])inf rows:(int)rows padding:(CGPoint)padding { CCMenuItem *dummy = (CCMenuItem *)[menu.children objectAtIndex:0]; int itemIndex = 0; float w = dummy.contentSize.width; float h = dummy.contentSize.height; CGSize screenSize = [[CCDirector sharedDirector]winSize]; CCArray *items = [menu children]; float startX; for (int i = rows - 1; i &gt;=0; i--) { int colsNow = info[i].cols; startX = (screenSize.width - (colsNow * w + padding.x * (colsNow - 1)))/2; float y = i * (padding.y + h); for (int j = 0; j &lt; colsNow; j++) { CCMenuItem *item = (CCMenuItem *)[items objectAtIndex:itemIndex]; item.anchorPoint = ccp(0,0); item.position = ccp(startX, y); startX += padding.x + w; itemIndex++; } } } </code></pre> <p>The call goes like this(a custom keyboard):</p> <pre><code>//create custom keyboard NSArray *captions = [NSArray arrayWithObjects: @"Q", @"W", @"E", @"R", @"T", @"Y", @"U", @"I", @"O", @"P", @"A", @"S", @"D", @"F", @"G",@"H", @"J", @"K", @"L", @"Z", @"X", @"C", @"V", @"B", @"N", @"M", nil]; CCMenu *menu = [CCMenu menuWithItems:nil]; [self addChild:menu]; for (NSString *caption in captions) { CCLabelTTF *label = [CCLabelTTF labelWithString:caption fontName:@"Courier" fontSize:25]; CCMenuItemLabel *item = [CCMenuItemLabel itemWithLabel:label target:self selector:@selector(callDelegate:)]; [menu addChild:item]; } RowInfo info[3] = {{7}, {9}, {10}}; //inverse order [self layoutMenu:menu withRowInfo:info rows:3 padding:ccp(15, 15)]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload