gpt4 book ai didi

iOS 6 和 iOS 7 UIButton 标签垂直对齐

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:17:30 24 4
gpt4 key购买 nike

当我尝试对齐 uibutton 文本标签时出现问题。在 ios6 上它位于中心,但在 ios7 上它大约低 4 像素。

按钮类

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
[self setBackgroundImage:[UIImage imageNamed:@"circle"] forState:UIControlStateNormal];
[self.titleLabel setFont:[UIFont seBoldUserFontOfSize:13.0]];

_numberLabel = [[IBMSmallDescriptionTextLabel alloc] initWithFrame:CGRectMake(5.5, 0, 18, 18)];
[self addSubview:_numberLabel];
}
return self;
}

在自定义标题中:

- (void)createButtons
{
for (int i = 0; i <= 5; i++)
{
IBMStageButton *button = [[IBMStageButton alloc] initWithFrame:CGRectMake(18.0 + (60.0 * i), 1.0, 18.0, 18.0)];
[button.numberLabel setText:[NSString stringWithFormat:@"%d", i+1]];
[self addSubview:button]; // self frame W320 H23
}
}

最佳答案

我有这个。我使用:

if (iOS_7_or_later) {
[button setTitleEdgeInsets:UIEdgeInsetsMake(2, 0, 0, 0)];
}

iOS_7_or_later 只是我使用的一个宏:

#define iOS_7_or_later SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

关于iOS 6 和 iOS 7 UIButton 标签垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19058154/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com