简体   繁体   English

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

[英]iOS 6 and iOS 7 UIButton label vertical align

There is a problem when i try to align uibutton textlabel. 当我尝试对齐uibutton textlabel时出现问题。 on ios6 it's in center, but on ios7 it's about 4pixels lower. 在ios6上它居中,但在ios7上大约低4像素。

Button class 按钮类

- (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;
}

In custom header: 在自定义标题中:

- (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
    }
}

I had this. 我有这个 I use: 我用:

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

The iOS_7_or_later is just a macro i use: 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM