2012-11-23 53 views
0

我必須製作自定義按鈕。問題在於按鈕上的文字未居中對齊。 我製作與UIButton框架相同框架大小的文本標籤。 文本標籤的文本對齊方式爲中心。自定義用戶界面按鈕上的文本對齊

但它並不完全在中心。它在右側。

+0

在您的代碼中可能只是一個錯誤。張貼在這裏,我們會看看它。 – Martol1ni

回答

0

試試這個

label.textAlignment = UITextAlignmentCenter; 
0

嘗試設置爲textLabel的框架以下列方式:

textLabel.frame = CGRectMake(0,0,button.frame.size.width, button.frame.size.height); 
+0

其實我不得不從中心左側設置標籤只有1,2個像素。 – Waqas

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); 
0

其實我不得不設置標籤上左側距離市中心僅1,2像素..

我剛剛用這個了我的問題的決心..

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