【问题标题】:Can I set offset position on Storyboard?我可以在情节提要上设置偏移位置吗?
【发布时间】:2017-08-25 04:39:56
【问题描述】:

我可以在 Storyboard 上像下面的代码那样写吗?

let button = UIButton()
button.titleLabel.center = CGPoint(x:button.titleLabel.center.x, y:button.titleLabel.center.y + 30)

【问题讨论】:

  • 嗯,你做到了,尝试编译并执行它。如果它没有按您希望的方式工作,请发布更具体的问题。

标签: swift uibutton autolayout storyboard


【解决方案1】:

查看UIEdgeInsets 和 UIButton 属性titleEdgeInsets

button.titleLabelInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 30)

根据您的确切需求和代码,这应该可以满足您的需求。 (仅供参考 - 还有一个 imageEdgeInsets。)

【讨论】:

  • 非常感谢。这正是我想要的。我不知道这个属性。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-22
  • 2014-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多