相关疑难解决方法(0)

如何使按钮闪烁或闪烁?

我试图在扫描正确时将按钮的颜色(只是闪烁/闪烁)更改为绿色,在出现问题时将其更改为红色.我可以用这样的观点来做到这一点

func flashBG(){
    UIView.animateWithDuration(0.7, animations: {
        self.view.backgroundColor = UIColor.greenColor()

    })
}
Run Code Online (Sandbox Code Playgroud)

但是有一个按钮它会保持绿色

func flashBtn(){
    UIButton.animateWithDuration(0.5, animations: {
        self.buttonScan.backgroundColor = UIColor.greenColor()
    })
}
Run Code Online (Sandbox Code Playgroud)

我已经按代码创建了按钮

func setupScanButton() {
    let X_Co = (self.view.frame.size.width - 100)/2
    let Y_Co = (self.viewForLayer.frame.size.height + 36/2)

    buttonScan.frame = CGRectMake(X_Co,Y_Co,100,100)
    buttonScan.layer.borderColor = UIColor.whiteColor().CGColor
    buttonScan.layer.borderWidth = 2
    buttonScan.layer.cornerRadius = 50
    buttonScan.setTitle("Scan", forState: .Normal)
    buttonScan.backgroundColor = UIColor.blueColor()
    buttonScan.addTarget(self, action: "buttonScanAction", forControlEvents: .TouchUpInside)
    buttonScan.setTitleColor(UIColor(red:255/255, green: 255/255, blue:255/255, alpha: 1), forState: UIControlState.Normal)

    self.view.addSubview(buttonScan)
}
Run Code Online (Sandbox Code Playgroud)

我应该再次调用setupScanButton()吗?

uibutton ios swift

14
推荐指数
5
解决办法
2万
查看次数

标签 统计

ios ×1

swift ×1

uibutton ×1