2014-06-23 73 views
0

我想在我的UIButton CGRect中心(x軸和y軸)這個+符號,但是它一直向下推進y軸。在其框架中居中放置一個UIButton標題

UIButton *aButton = [UIButton buttonWithType:UIButtonTypeSystem]; 
[aButton setTitle:@"+" forState:UIControlStateNormal]; 
[aButton.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:(40.0)]]; 
[aButton setBackgroundColor:[UIColor grayColor]]; 
[aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
[aButton setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted]; 

aButton.layer.cornerRadius = 25.0; 

aButton.frame = CGRectMake(75.0, 100.0, 50.0, 50.0); 

回答

1

如果你有上升和下降,這樣看起來更加正確。該按鈕內有一個標籤,其大小適合該字體的所有可能字符的高度。如果你不喜歡標籤的位置,你可以自由移動它。有很多方法可以做到這一點;例如,您可以嘗試使用按鈕的titleEdgeInsets

+0

喔,你如何移動的標籤。添加一個UILabel然後選擇它的中心起源? – cdub

+0

一個按鈕是非常可定製的。看看文檔... – matt

+0

我感謝一噸 – cdub

0

加入這一行設置標題和字體後:

aButton.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 9, 0); 
相關問題