首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以编程方式链接按钮

以编程方式链接按钮
EN

Stack Overflow用户
提问于 2014-03-12 14:46:51
回答 2查看 71关注 0票数 0

我正在设计一个应用程序,它要求我有一个按钮网格,每个按钮都有四个不同的状态。未选定、选定、命中或错过。我试图通过编程生成这些按钮,但是我很难只选择其中一个按钮。是否有一种方法可以将它们放入数组中,然后迭代数组以取消它们?我查看了IBOutletCollections,但是这些都无法工作,因为我想以编程方式创建这些按钮。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-11 19:38:22

这适用于我,其中_lastSelectedButton是最后选定按钮的id,宽度为25。

代码语言:javascript
复制
-(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

{

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2014-03-12 15:22:33

我认为也许您应该检查一下我在开发iPhone和iPad cs193p的iOS 7应用程序中学到的这个演示。

https://github.com/elilien/Matchismo

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22355105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档