小编dim*_*006的帖子

iOS Swift标签框架高度未正确更新

我有一个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)

height label frame ios swift

3
推荐指数
1
解决办法
1755
查看次数

将图像文件保存到临时目录

我有一个名为"Image.png"的图像文件,它保存在我的主包中(在Project Navigator层次结构中的ViewController.swift文件旁边).我想将此映像的副本保存到临时目录.我以前从未做过,我可以使用哪些代码?

image temporary-directory ios swift

2
推荐指数
3
解决办法
1万
查看次数

标签 统计

ios ×2

swift ×2

frame ×1

height ×1

image ×1

label ×1

temporary-directory ×1