我有一个UIButton。我想让它在屏幕上随机生成。它不返回错误,并运行,但屏幕上没有显示任何内容。我试过对这些值进行严格的编码,这是可行的。我在用斯威夫特。
代码:
import UIKit
class ViewController: UIViewController {
let changingPoint = UIButton()
let dot = UIImage(named: "sponsor-dot.png")
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
changingPoint.setImage(dot, forState: .Normal)
changingPoint.addTarget(self, action: "pointPressed:", forControlEvents: .TouchUpInside)
changingPoint.frame = CGRectMake(CGFloat(arc4random()%(320)), CGFloat(arc4random()%(568)), 150, 150)
self.view.addSubview(changingPoint)
}
func pointPressed(sender: UIButton!) {
changingPoint.frame = CGRectMake(CGFloat(arc4random()%(320)), CGFloat(arc4random()%(568)), 150, 150)
println()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}发布于 2014-06-09 03:52:33
我相信你没有为按钮设置背景色。
changingPoint.backgroundColor = UIColor.blackColor() //or any other color that you wanthttps://stackoverflow.com/questions/24113349
复制相似问题