我有一个奇怪的问题。我有一个带有自定义背景和一个字符作为标题的 UIButton。我希望按钮通过动画变大。动画有效,但是,我再也看不到按钮的标题了。
这是我的代码:
UIButton *letterButton = [UIButton buttonWithType:UIButtonTypeCustom];
[letterButton.titleLabel setFont:[UIFont boldSystemFontOfSize:18.0f]];
[letterButton setTitle:[gameManager letterTextForIndex:curIndex] forState:UIControlStateNormal];
letterButton.frame = CGRectMake(curX + kLetterButtonSize / 2, curY + kLetterButtonSize / 2, 0.01f, 0.01f);
[letterButton addTarget:self action:@selector(pressedLetterButton:) forControlEvents:UIControlEventTouchUpInside];
UIImage *buttonImage = [[UIImage imageNamed:@"blueButton.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];
UIImage *buttonImageHighlight = [[UIImage imageNamed:@"blueButtonHighlight.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];
[letterButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[letterButton setBackgroundImage:buttonImageHighlight forState:UIControlStateHighlighted];
[self.view addSubview:letterButton];
[UIButton animateWithDuration:0.20f delay:curIndex * 0.17f options:UIViewAnimationOptionTransitionNone animations:^
{
letterButton.transform = CGAffineTransformMakeScale(kLetterButtonSize / 0.01f, kLetterButtonSize / 0.01f);
}
completion:^(BOOL finished)
{
[letterButton setTitle:[gameManager letterTextForIndex:curIndex] forState:UIControlStateNormal];
}];
如您所见,我从一个非常小的按钮开始,然后进行转换,随着时间的推移,我使按钮变大。我动态计算我的按钮的比例因子是多少。
谁能向我解释为什么按钮的标题不可见?