我想在我的 UIButton CGRect 中将这个 + 符号居中(x 轴和 y 轴),但它一直被推到 y 轴下。
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);
最佳答案
如果您有上升部分和下降部分,这对您来说看起来会更正确。按钮内有一个标签,其大小可容纳该字体的全部可能字符的高度。如果您不喜欢标签的位置,可以随意移动它。有很多方法可以做到这一点;例如,您可以尝试使用按钮的 titleEdgeInsets
。
关于ios - 将 UIButton 标题置于其框架的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24356966/