Search code examples
iosobjective-ccocos2d-iphonexcode5

Unable to set Left Alignment for button title in Cocos2d


It's very easy to Left-Align CCLabelTTF, but CCButton seems to have a problem with alignments.

setting button.horizontalpadding = CCTextAlignmentLeft; has no affect on button alignment. I have attempted to modify properties preferredSize and contentSize in order to create boxes for alignment without success.


Solution

  • I dont this there is a CCButton class in cocos2d. I assume you are talking about CCMenuItelLabel. Try this way:

            CGPoint rightAlligned = ccp(1.0f, 0.5f);
            CGPoint leftAlligned = ccp(0.0f, 0.5f);
    
    
       button.label.anchorPoint = leftAligned; //For left text align
       button.label.anchorPoint = rightAligned; //For right text align