2

当我尝试对齐 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
    }
}
4

1 回答 1

6

我有这个。我用:

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)
于 2013-09-27T19:01:22.053 回答