Я довольно новичок в использовании XCode и Swift, поэтому я хочу знать, как перемещать UILabel. Вот мой код:Как переместить UILabel с помощью других UIButton?
@IBAction func startButton(_ sender: UIButton) {
sender.isHidden = true
drawtarget()
}
var hosPos = Int(arc4random_uniform(253)) + 10
var verPos = 580
func drawtarget() {
let button = UIButton(frame: CGRect(x: hosPos, y: verPos, width: 47, height: 47))
button.backgroundColor = UIColor(red: 102/255, green: 205/255, blue: 255/255, alpha: 1.0)
button.layer.cornerRadius = 0.5 * button.bounds.size.width
button.addTarget(self, action: #selector(foo(sender:)), for: .touchUpInside)
view.addSubview(button)
}
func creatingShot(_ sender: UILabel) {
let shot = UILabel(frame: CGRect(x: 217, y: 50, width: 8, height: 8))
shot.backgroundColor = UIColor.green
shot.text = ""
view.addSubview(shot)
}
func foo(sender: UIButton) {
sender.isHidden = true
perform(#selector(drawtarget), with: nil, afterDelay: 3.0)
hosPos = Int(arc4random_uniform(253)) + 10
verPos = 600
}
Итак, мне нужно переместить выстрел (UILabel) в центр кнопки (UIButton, что нажата). Есть идеи?