简体   繁体   English

UIKit 以编程方式:UILabel 从顶部被切断

[英]UIKit Programmatically: UILabel gets cut off from the top

I have a UILabel in a UINavigationController. I want the label to be a little bit below the navigation bar title.我在 UINavigationController 中有一个 UILabel。我希望 label 位于导航栏标题下方一点。

I've applied these constraints to the label:我已将这些约束应用于 label:

let greetingsLabelConstraints = [
   greetingsLabel.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
   greetingsLabel.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),
]
    

it does position itself correctly but the label is cut off from the top, seems like the height is not enough so the container's height is cutting half of the label off.它本身正确地执行 position 但 label 从顶部被切断,似乎高度不够所以容器的高度将 label 的一半切断。

Although, when I add a bottom constraint, the label is not being cut off, but then the position is not correct.虽然,当我添加底部约束时,label 没有被切断,但是 position 是不正确的。

I tried multiple fixes like:我尝试了多种修复,例如:

label.clipToBounds = false
label.baselineAdjustment = .none
label.lineBreakMode = .byCharWrapping
label.sizeToFit()

Nothing worked, what could be the issue?没有任何效果,可能是什么问题?

Okay, so I managed to solve it just by replacing the font with a different one.好的,所以我设法通过用不同的字体替换字体来解决它。 I was using Damascus, and for some reason, it was giving me some problems regarding the right height container of the label.我正在使用大马士革,出于某种原因,它给我带来了一些关于 label 的正确高度容器的问题。

After switching to almost any other iOS font, it was working perfectly fine.在切换到几乎任何其他 iOS 字体后,它工作得非常好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM