我已经设法让这打印的相对高度数据到日志,但我想做的是让它打印到指定的label.Any帮助将不胜感激。
import UIKit
import CoreMotion
class ViewController: UIViewController {
@IBOutlet weak var altitudeLabel: UILabel!
let altimeter = CMAltimeter()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func start(sender: AnyObject) {
if CMAltimeter.isRelativeAltitudeAvailable() {
altimeter.startRelativeAltitudeUpdatesToQueue(NSOperationQueue.mainQueue(), withHandler: { data, error in
if (error == nil) {
println("relative Altitude: \(data.relativeAltitude)")
println("Pressure: \(data.pressure)")
}
})
}
}
}发布于 2015-02-27 16:19:08
您可以使用以下行为UILabel插座分配一个带两位小数点的浮点值:
self.altitudeLabel.text = String(format: "%0.2f", data.relativeAltitude)发布于 2015-03-01 08:33:49
我最终使用了这个,它将在现在到期:
var myIntValue:Int = Int(data.relativeAltitude)
println ("My value is \(myIntValue)")
self.altitudeLabel.text = ("\(myIntValue) M")https://stackoverflow.com/questions/28760067
复制相似问题