gpt4 book ai didi

ios - 无法在标签与其边框之间添加空格

转载 作者:搜寻专家 更新时间:2023-11-01 06:28:42 26 4
gpt4 key购买 nike

我有一个带有矩形边框的标签。我想在标签的文本和标签的边框之间添加空格。
我尝试按照此处描述的步骤操作:https://stackoverflow.com/a/40385630/9735046

myLabel.frame.size.width = myLabel.intrinsicContentSize.width + 10
myLabel.frame.size.height = myLabel.intrinsicContentSize.height + 10
myLabel.textAlignment = .center

但它并没有在我的标签文本和边框之间添加空格。
我将如何添加空间?

最佳答案

问题出在viewDidLoad frame is not to be set so try this

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.



lb.text = "dbjsjdhsjhdshjdshjdshdjs"

lb.layer.borderColor = UIColor.red.cgColor

lb.layer.borderWidth = 3

lb.textAlignment = .center

view.addSubview(lb)

lb.sizeToFit()

lb.center = view.center
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

lb.frame.size.width = lb.intrinsicContentSize.width + 100

lb.frame.size.height = lb.intrinsicContentSize.height + 100

lb.center = view.center

}

//

enter image description here

关于ios - 无法在标签与其边框之间添加空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50292911/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com