我有一个Label,每次用户单击Button时,其文本都会更改。但是,即使Label内容已更改,Label.frame.height值也不会立即更新。更改Label的函数在多个位置调用,但是高度仅在@IBAction块内部更新,其值滞后一个单击周期。我的代码如下:
func changeLabelText() {
//Here I have an algorithm (not shown) that generates myMutableString
Label.attributedText = myMutableString //Label is updated.
}
@IBAction func changeLabelButton(sender: UIButton) {
print("1. Height = ", Label.frame.height) //Height updates here, but it's the old value.
changeLabelText() //Label is updated.
print("2. Height = ", Label.frame.height) //Returns same height as Line 1!!
}
override func viewDidLoad() {
super.viewDidLoad()
print("3. Height = ", Label.frame.height) //Initially, height is 21.0 when ViewController first loads.
changeLabelText() //Label is updated.
print("4. …Run Code Online (Sandbox Code Playgroud) 我有一个名为"Image.png"的图像文件,它保存在我的主包中(在Project Navigator层次结构中的ViewController.swift文件旁边).我想将此映像的副本保存到临时目录.我以前从未做过,我可以使用哪些代码?