【发布时间】:2017-07-31 10:26:12
【问题描述】:
当我单击 UIButton 时,我希望它更改其文本颜色。此外,我在每个按钮下方设置了一个视图,该按钮的下边距为 7。我这样做是为了通过更改视图的背景颜色为单击的按钮提供突出显示的效果。单击按钮时没有任何反应。这里附上截图
我希望它在点击时完全像这样
- (IBAction)setMenubtn:(UIButton *)menubtn:(id)sender {
[self.menubtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.contactsbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.favoritesbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.topView setBackgroundColor:[UIColor colorWithRed:2/255 green:115/255 blue:168/255 alpha:1]];
[self.topview2 setBackgroundColor:[UIColor colorWithRed:226/255 green:226/255 blue:226/255 alpha:1]];
[self.topview3 setBackgroundColor:[UIColor colorWithRed:226/255 green:226/255 blue:226/255 alpha:1]];
}
- (IBAction)setContactsbtn:(UIButton *)contactsbtn:(id)sender {
[self.menubtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.contactsbtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.favoritesbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.topView setBackgroundColor:[UIColor colorWithRed:226/255 green:226/255 blue:226/255 alpha:1]];
[self.topview2 setBackgroundColor:[UIColor colorWithRed:2/255 green:115/255 blue:168/255 alpha:1]];
[self.topview3 setBackgroundColor:[UIColor colorWithRed:226/255 green:226/255 blue:226/255 alpha:1]];
}
- (IBAction)setFavoritesbtn:(UIButton *)favoritesbtn:(id)sender {
[self.menubtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.contactsbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.favoritesbtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[self.topView setBackgroundColor:[UIColor colorWithRed:226/255 green:226/255 blue:226/255 alpha:1]];
[self.topview2 setBackgroundColor:[UIColor colorWithRed:226/255 green:226/255 blue:226/255 alpha:1]];
[self.topview3 setBackgroundColor:[UIColor colorWithRed:2/255 green:115/255 blue:226/255 alpha:1]];
}
它正在显示这个输出
【问题讨论】:
-
尝试添加 .f 作为后缀。喜欢- [UIColor colorWithRed:226.f/255.f green:226.f/255.f blue:226.f/255.f alpha:1];
-
这里
sender有什么用 -
这是正确的
(IBAction)setMenubtn:(UIButton *)menubtn:(id)sender否则 -
应该是 --> (IBAction)setMenubtn:(UIButton *)menubtn
-
@Anbu.Karthik 什么都没发生
标签: ios objective-c uibutton