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