简体   繁体   English

iOS:实现(扫雷风格)按钮网格的最佳方法

[英]iOS: Best way to implement a (Minesweeper style) grid of buttons

I've created a prototype of an iOS app. 我已经创建了一个iOS应用程序的原型。 It's a game based on pressing a grid of buttons, with the labels changing depending on which buttons you pressed. 这是一款基于按下按钮网格的游戏,标签根据您按下的按钮而变化。 In that sense it's a lot like Minesweeper. 从这个意义上讲,它很像扫雷舰。

I did this by making 64 individual buttons, and creating an outlet and an action for each by control-dragging to the .h file 128 times. 为此,我制作了64个单独的按钮,并通过将每个控件拖到.h文件中的方法分别为128个创建了一个出口和一个动作。 It was a bit laborious. 这有点费力。 I then needed to copy (with minor changes) the code for each outlet and action 64 times. 然后,我需要复制(稍作更改)每个出口的代码并执行64次操作。 Again, laborious. 再次,费力。

Now I want to make a new version with a bigger grid: 122 buttons. 现在,我想用更大的网格制作一个新版本:122个按钮。 So I'd like to implement it more intelligently. 因此,我想更智能地实施它。 Any ideas? 有任何想法吗? Is there some sort of 'grid button' that could be used instead? 是否可以使用某种“网格按钮”代替?

The best way would be to use a UICollectionView , its like a tableview but in gridformat(depending on ho you want to show your cells). 最好的方法是使用UICollectionView ,它类似于UICollectionView ,但采用gridformat格式(取决于要显示单元格的位置)。 Here's an example of http://www.raywenderlich.com/78550/beginning-ios-collection-views-swift-part-1 这是http://www.raywenderlich.com/78550/beginning-ios-collection-views-swift-part-1的示例

And after a quick search i also found a GitHub repo with a minesweeper made with UICollectionView: https://github.com/AdamGluck/minesweeper 快速搜索后,我还找到了一个使用UICollectionView制作的扫雷器的GitHub存储库: https : //github.com/AdamGluck/minesweeper

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM