简体   繁体   English

(迅速)有人可以帮助我对这些按钮进行大量更改吗?

[英](swift) Anyone can help me to make bulk change to those buttons?

here is the screenshot 这是屏幕截图

when user get into this page, I want to change the background of those button. 当用户进入此页面时,我想更改这些按钮的背景。 for example, when the level of user is 6, I want to change the top 6 background of buttons to a blue picture as first button. 例如,当用户级别为6时,我想将按钮的前6个背景更改为蓝色图片作为第一个按钮。 I don't wanna write a code one by one, so please help me to write a function, Thank you very much! 我不想一一编写代码,所以请帮助我编写一个函数,非常感谢!

You can add you buttons to the array in order of increasing level and do something like this: 您可以按级别递增的顺序将按钮添加到数组,并执行以下操作:

var buttons: [UIButton] // array of your buttons, next you need to init it
...
func setColorForUserLevel(userLevel: Int) {
    if userLevel > buttons.count {
        return
    } else {
        for i in 0...userLevel - 1 {
            buttons[i].backgroundColor = UIColor.blueColor()
        }
    }
}

I create simple example project to show how to use it: 我创建一个简单的示例项目来展示如何使用它:

  1. I have outlets with UIButton! 我有带UIButton!商店UIButton! type and buttons object in code: 类型和buttons对象在代码中: 在此处输入图片说明

  2. And i test setColorForUserLevel function in viewDidLoad method: 我在viewDidLoad方法中测试setColorForUserLevel函数:

    override func viewDidLoad() { super.viewDidLoad() 覆盖func viewDidLoad(){super.viewDidLoad()
    buttons = [button1, button2, button3] setColorForUserLevel(2) } button = [button1,button2,button3] setColorForUserLevel(2)}

暂无
暂无

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

相关问题 我想快速制作一个翻译应用程序。 谁能帮我? - I want to make a translation app in swift. Can anyone help me? 谁能帮我解决在 Xcode 上使用 swift 从 Firebase 检索数据的问题? “源文件中的编辑器占位符” - Can anyone help me with this issue of retrieving data from Firebase using swift on Xcode? “Editor placeholder in source file” 有没有人可以帮助我完成我的 Swift 项目? 我有一个 Firebase 错误 - Is there anyone who can help me with my Swift Project? Ive got an Firebase error 任何人都可以帮助我解决 swift 4 中以下问题的类和方法的使用 [暂停] - Can anyone help me out with the usage of classes and methods for the following problem in swift 4 please [on hold] 使用Xib和Swift的iOS本地化:有人可以帮助我使用XIB(不是Storyboard)和Swift制作多语言应用程序吗? - iOS Localization using Xib & Swift: Can someone help me to make an multilingual app using XIB (not Storyboard) and Swift? 谁能帮助我使用 swift 实现具有不同半径和角度的 coxcomb 饼图? 我想实现饼图 - can anyone help me out for implementation of coxcomb pie chart with different radii and angles using swift? i want to implement pie chart 谁能帮我这个? 我无法理解这个 - can anyone help me with this ? I can't understand this 您能帮我理解这种Swift方法吗? - Can you help me understand this Swift method? 谁能给我一个关于 iOS Swift 单元测试的例子? - Can anyone give me an example about unit testing in iOS Swift? 谁能帮我理解这段代码-iOS Swift - Can anybody help me understand this code - iOS swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM