我正在设计一个应用程序,要求我具有四种不同状态的按钮网格。 Unselected,Selected,Hit或Miss。我试图以编程方式生成这些按钮,但我遇到了麻烦,只保留其中一个按钮。有没有办法,也许我可以把它们放入一个数组,然后迭代数组以取消选择它们?我看着IBOutletCollections但这些不会起作用,因为我要创建这些按钮编程以编程方式链接的按钮
0
A
回答
0
这为我工作,其中_lastSelectedButton是最后的选择按钮的ID,宽度是25
-(void)unselect
{
if(_lastSelectedButton){
//Unselect the last selected button However only change its background if is blue
[[_lastSelectedButton layer] setBorderWidth:0.0f];
if([_lastSelectedButton.titleLabel.text isEqual: @"0"]){
[[_lastSelectedButton layer] setBackgroundColor:[missColor CGColor]];
}else if([_lastSelectedButton.titleLabel.text isEqual: @"/"]){
[[_lastSelectedButton layer] setBackgroundColor: [hitColor CGColor]];
}
else{
[[_lastSelectedButton layer] setBackgroundColor:unselectedColor.CGColor];
}
}
_lastSelectedButton = nil;
}
- (void)advanceSelection:(UIButton*)sender
{
int i = 0;
//Find the indice that the present selected thing is
for(UIButton *button in btnList)
{
if(sender == button)
{
if((i >= (self.numberOfPlayers - 1) * width) &&((i + 1) % 5 == 0)){
//Then animated scroll to the next frame
if (i + 1 == self.numberOfPlayers * width) {
//then it is the last button
[self unselect];
}else{
CGFloat x = (([_pageControl currentPage] + 1.0) * 320.0);
[_scrollView setContentOffset:CGPointMake(x, 0.0f) animated:YES];
[self selection:btnList[i - (width * (self.numberOfPlayers - 1)) + 1]];
[self scrollViewDidEndDecelerating:self.scrollView];
self.pageControl.currentPage = _pageControl.currentPage + 1;
}
}else if(i >= ((self.numberOfPlayers - 1) * width)){
//We want to move it up one
//subtract width times hieght and ad one
[self selection:btnList[i - (width * (self.numberOfPlayers - 1)) + 1]];
}else{
//To go one down add 25 (the width)
[self selection:btnList[i + 25]];
}
}
i++;
}
}
0
相关问题
- 1. 以编程方式向Outlook 2007添加超链接按钮
- 2. 以编程方式按下按钮
- 3. iPhone:以编程方式按下按钮
- 4. 以编程方式按下此按钮
- 5. 以编程方式编写android:按钮
- 6. Android以编程方式声明按钮?
- 7. 以编程方式点击按钮vb.net
- 8. 以编程方式点击HTML按钮
- 9. 以编程方式单击MessageBox按钮
- 10. 以编程方式点击按钮 - JS
- 11. 以编程方式居中按钮
- 12. 以编程方式IBAction和按钮
- 13. 以编程方式添加按钮
- 14. 以编程方式禁用按钮
- 15. 以编程方式切换按钮on_state?
- 16. 以编程方式设置RoundedRect按钮
- 17. 以编程方式创建的向导控制中禁用链接按钮
- 18. 以编程方式链接CNContacts
- 19. 以编程方式点击JQuery链接
- 20. 以编程方式触发UIWebView中的链接长按
- 21. 执行Segue以编程方式没有按钮连接?
- 22. 以编程方式连接按钮XCode9,Objective-C,OSX
- 23. 如何以编程方式生成按钮名称按钮
- 24. 编程选择超链接按钮
- 25. 以编程方式设置按钮对齐方式
- 26. 以编程方式设置等效于按钮的按键
- 27. 以编程方式按下Sencha触摸按钮的Greasemonkey脚本
- 28. 设置WPF按钮式编程方式
- 29. 以编程方式调用按钮的点击方法
- 30. 以编程方式更改按钮的onClick方法?
听起来像是你已经知道答案: “把它们放到一个数组中,然后迭代数组以取消选择它们” - 这应该起作用 – dariaa
NSArray引用是“强壮的”。 –