押されたときにサイズと色を変更する必要がある 2 つの UIButtons を持つアプリに取り組んでいます。私のコードは次のとおりです。
UIButton *Answer1Button = [UIButton buttonWithType:UIButtonTypeCustom];
UIButton *Answer2Button = [UIButton buttonWithType:UIButtonTypeCustom];
[Answer1Button addTarget:self action:@selector(Answer1Action) forControlEvents:UIControlEventTouchUpInside];
[Answer2Button addTarget:self action:@selector(Answer2Action) forControlEvents:UIControlEventTouchUpInside];
[Answer1Button setBackgroundColor:[UIColor redColor]];
[Answer2Button setBackgroundColor:[UIColor yellowColor]];
Answer1Button.frame = CGRectMake(0, 0, 320, 45);
Answer2Button.frame = CGRectMake(0, 50, 320, 45);
そして、私が作成した関数:
-(void)Answer1Action{
[UIButton beginAnimations:nil context:nil];
[UIButton setAnimationDuration:0.5];
self.backgroundColor = [UIColor greenColor];
self.alpha = 0.5;
[UIButton commitAnimations];
}
私が今遭遇する問題は、UIButton を押すと関数が呼び出されますが、self.alpha はボタンが配置されている UIView 全体に影響します。
私はまだ Objective-C の新人なので、忘れていた簡単なことだと思います。