2014-06-23 36 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); 
相关问题