0

我必须制作一个自定义按钮。问题是按钮上的文本没有居中对齐。我制作与框架相同的框架大小的文本标签UIButton。并且文本标签的文本对齐方式为居中。

但它并不完全在中心。它在右侧。

4

4 回答 4

0

如果你使用 cocos2d 试试这个:

//Take Size of the screen
CGSize winSize = [CCDirector sharedDirector].winSize;

//puts the label in the center of the screen
label.position = ccp(winSize.width/2,winSize.height/2);
于 2012-11-23T13:19:17.020 回答
0

尝试这个

label.textAlignment = UITextAlignmentCenter;
于 2012-11-23T12:19:23.360 回答
0

尝试通过以下方式设置 textLabel 的框架:

textLabel.frame = CGRectMake(0,0,button.frame.size.width, button.frame.size.height);
于 2012-11-23T12:23:13.243 回答
0

实际上,我必须将标签设置在距中心左侧仅 1,2 像素的位置。

我刚刚用这个解决了我的问题..

[okButton setContentHorizo​​ntalAlignment:UIControlContentHorizo​​ntalAlignmentLeft]; [okButton setContentVerticalAlignment:UIControlContentVerticalAlignmentTop]; [okButton setTitleEdgeInsets:UIEdgeInsetsMake(13.0,27.0, 0.0, 0.0)];

于 2012-11-23T13:46:04.973 回答