gpt4 book ai didi

ios - 如何使用其他按钮添加到 UIStepper 值?

转载 作者:行者123 更新时间:2023-11-30 13:58:15 25 4
gpt4 key购买 nike

我有一个 UIStepper,它对 UILabel 递增/递减 1,我想要一个额外的 +3 按钮,当按下 +3 会向标签添加 3,但如果按下 UIStepper,它会返回到 1。

我的代码如下:

import Foundation
import UIKit
import AVFoundation


class ViewTwo : UIViewController, AVAudioPlayerDelegate {

override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent
}

/// Actions de sonido -------
@IBAction func stepperSoundRed(sender: UIStepper) {
audioPlayer.play()
}
@IBAction func stepperSoundBlue(sender: UIStepper) {
audioPlayer.play()
}
/////////////////////////

// el nombre del equipo Blue
@IBOutlet weak var teamBlueTextLabel: UILabel!
var BlueName = String()

// nombre del equipo rojo
@IBOutlet weak var teamRedTextLabel: UILabel!
var RedName = String()

// score inicial del equipo rojo
@IBOutlet weak var RedScoreLabel: UILabel!
var RedScore = String()

// score initcial equipo azul
@IBOutlet weak var BlueScoreLabel: UILabel!
var BlueScore = String()

// que funcionen los Steppers
@IBOutlet weak var RedStepperUI: UIStepper!
@IBOutlet weak var BlueStepperUI: UIStepper!

// Botón Done
@IBOutlet weak var BotonDone: UIButton!

@IBAction func BlueStepperValueChange(sender: UIStepper) {
BlueScoreLabel.text = Int(sender.value).description
}

@IBAction func RedStepperValueChange(sender: UIStepper) {

RedScoreLabel.text = Int(sender.value).description

}


@IBOutlet weak var periodUILabel: UILabel!





// archivos de sonidos
var sound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("ping2", ofType: "mp3")!)
var audioPlayer = AVAudioPlayer()

required init? (coder aDecoder: NSCoder){
super.init(coder: aDecoder)
do {
try audioPlayer = AVAudioPlayer(contentsOfURL: sound, fileTypeHint: nil)
audioPlayer.prepareToPlay()
audioPlayer.delegate = self
//audioPlayer.play()

} catch {
// Errors here
}
}
@IBAction func BackToViewOne(sender: UIButton) {
self.dismissViewControllerAnimated(true, completion: nil)
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Landscape
}

// Period


@IBOutlet weak var periodUILabel2: UILabel!

@IBAction func periodAdd1(sender: UIButton) {

if(periodUILabel.text == "20") {

}
else {
let period = Int(periodUILabel.text!)!+1
periodUILabel.text = String(period)
}

}

@IBAction func periodMinus1(sender: UIButton) {

if(periodUILabel.text == "0") {

}
else {
let period = Int(periodUILabel.text!)!-1
periodUILabel.text = String(period)
}
}

// VIEW DID LOAD

override func viewDidLoad() {


// No se para que es esto??
super.viewDidLoad()

BotonDone.layer.cornerRadius = 5

// Checamos si están vacios los nombres
if BlueName.isEmpty {
BlueName = "BLUE"
}

if RedName.isEmpty {
RedName = "RED"
}
if RedScore.isEmpty {
RedScore = "0"
}
if BlueScore.isEmpty {
BlueScore = "0"
}


// Proseguimos a asignarlos a las Labels

teamBlueTextLabel.text = BlueName
teamRedTextLabel.text = RedName
RedScoreLabel.text = RedScore
BlueScoreLabel.text = BlueScore


// Aqui vemos el Red +/-
RedStepperUI.wraps = true
RedStepperUI.autorepeat = false
RedStepperUI.value = Double(RedScore)!
RedStepperUI.maximumValue = 999

// aqui vemos el Blue +/-
BlueStepperUI.wraps = true
BlueStepperUI.autorepeat = false
BlueStepperUI.value = Double(BlueScore)!
BlueStepperUI.maximumValue = 999

//
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
}


// BOTONES MAS +3

@IBAction func RedPlus3UIButton(sender: UIButton) {
let CurrentScoreRed = RedStepperUI.value;
RedScoreLabel.text = String (Int(CurrentScoreRed) + 3)
audioPlayer.play()
}


@IBAction func BluePlus3UIButton(sender: UIButton) {

audioPlayer.play()
}


// BOTONES + Y -


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let DestViewController : ViewThree = segue.destinationViewController as! ViewThree

DestViewController.FinalScoreBlue = BlueScoreLabel.text!
DestViewController.FinalScoreRed = RedScoreLabel.text!
DestViewController.TeamNameR1Label = teamRedTextLabel.text!
DestViewController.TeamNameB1Label = teamBlueTextLabel.text!
}
}









class MyButtons : UIButton {
required init(coder aDecoder: (NSCoder!)) {
super.init(coder: aDecoder)!
self.layer.cornerRadius = 5
self.layer.borderColor = UIColor.whiteColor().CGColor
self.layer.borderWidth = 1
}
}

这是+3按钮:

@IBAction func RedPlus3UIButton(sender: UIButton) {
let CurrentScoreRed = RedStepperUI.value;
RedScoreLabel.text = String (Int(CurrentScoreRed) + 3)
audioPlayer.play()
}

最佳答案

您需要更新步进器的value 属性。示例:

@IBAction func RedPlus3UIButton(sender: UIButton) {
RedStepperUI.value += 3
let CurrentScoreRed = RedStepperUI.value
RedScoreLabel.text = String(Int(CurrentScoreRed))
audioPlayer.play()
}

关于ios - 如何使用其他按钮添加到 UIStepper 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33326119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com