Tôi đang tạo các nút theo chương trình. Tôi muốn thay đổi màu nền nút trong khi sờ lên bên trong một lần nữa nó phải thiết lập trở lại màu sắc bình thường của mình sau khi nâng lên ngón tay của chúng tôi .....Thay đổi màu nền UIButton
nine = [UIButton buttonWithType:UIButtonTypeCustom];
[nine setFrame:CGRectMake(15, 105, 65, 40)];
[nine setTitle:@"9" forState:UIControlStateNormal];
[nine setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[nine setBackgroundColor:[UIColor cyanColor]];
[nine addTarget:self action:@selector(clickDigit:) forControlEvents:UIControlEventTouchUpInside];
[nine addTarget:self action:@selector(changeButtonBackGroundColor:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:nine];
// để thay đổi màu nền
-(void)changeButtonBackGroundColor:(id) sender
{
[nine setBackgroundColor:[UIColor redColor]];
}
Tại đây changeBackgroundColor method được tạo ra để thay đổi màu sắc của nút đó. nó thay đổi màu sắc.
"Chạm Up" là tương đương với nâng ngón tay của bạn. – dasdom
Vậy ... câu hỏi chính xác là gì? Bạn đã viết phương pháp cho các hành động bạn đã đăng ký chưa? Nếu có, bạn có thể thêm mã đó không. – DBD
Kiểm tra bài đăng này https://somethingaboutios.wordpress.com/2016/02/09/uibutton-backgroundcolor-for-uicontrolstateselected/ –