ios - 字体大小为 0 或 1 (swift3)

标签 ios swift uifont

我在项目中使用 OpenSans 字体,但是当我将其大小调整为大于 1 的值时,其大小不会改变。如果我将其大小设置为 0,它就会消失。我不明白为什么它会这样。谁能向我解释一下吗?

这是代码:

let RememberMe = UILabel(frame: CGRect(x: checkbox.frame.maxX + view.frame.width*0.05, y: 0, width: ForgetPasswordcontainer.frame.width*0.3, height: ForgetPasswordcontainer.frame.height/2))
RememberMe.text = "Remember Me"
RememberMe.font = UIFont(name: "OpenSans-Regular", size: 1)
RememberMe.textColor = Colors().blue
RememberMe.baselineAdjustment = .alignCenters
RememberMe.adjustsFontSizeToFitWidth = true
RememberMe.textAlignment = .center
ForgetPasswordcontainer.addSubview(RememberMe)

最佳答案

它不会因为这一行而改变:

RememberMe.adjustsFontSizeToFitWidth = true

无论您将大小设置为多少,一旦到达该行,您就会再次调整字体大小以适合包含文本的标签。删除该行或更改标签的框架。另外,由于它是自定义字体,您需要确保已在 Info.plist 中注册它。

关于ios - 字体大小为 0 或 1 (swift3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46333066/

相关文章:

ios - 如何在 ios 中获取 GCM 通知

ios - 错误 : Value of type string has no member componentsSeparatedByCharactersInSet

ios - 当我第一次打开应用程序时,我的导航栏字体不会更改为我的自定义字体

ios - iOS 7 时钟应用中计时器使用的字体

ios - 使用 NSUserdefaults 填充 UITableView

ios - C4Movie 未加载

ios - 使用 FBSDKShareButton 上传图片到 Facebook

objective-c - 如何使用swift实现C-Style回调函数?

Google Home 应用程序的 ios URL 方案

ios - 为什么某些 iOS 字体系列不支持 UIFontDescriptorTraitBold?