我在iOS中使用Swift的iOS。
直到最近,它一直在完美地工作,但是我现在不能覆盖我的按钮在故事板的高度?
由于某种原因,按钮的高度现在要小得多。我尝试为按钮设置高度约束,将按钮放在堆栈视图中,并设置为按比例填充,甚至没有运气地覆盖SDK中的按钮高度。
如果我将按钮更改为普通的UIButton,布局约束就能很好地工作。
这就是我运行应用程序时按钮的样子。

这就是我想要的按钮的外观尺寸明智。

发布于 2017-02-04 16:54:59
我也遇到过这个问题。其原因在升级指南中解释。
FBSDKLoginButtonUI在4.19.0中发生了变化。这个按钮现在显示的是“继续使用Facebook",而不是”登录Facebook“。按钮颜色从#3B5998更改为#4267B2。按钮高度现在固定在28,因为使用了更小的字体大小和更大的Facebook徽标周围的垫子。
到目前为止,我找到的唯一解决办法是将SDK版本降级为4.18.0 (它为我完成了任务)。
FB可能会在未来的SDK更新中解决这个问题(他们为许多人创建了...that)。
对于一个更永久的解决方案,我们可以看到导致这种情况的特定更改,在GitHub上。我发现最可疑的变化开始于194
[self addConstraint:[NSLayoutConstraint constraintWithItem:self
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:28]];如果删除/禁用了上述约束,则可以帮助扭转这种情况。它应该大致如下所示(在编写本文时,我手头没有IDE ):
// Obtain all constraints for the button:
let layoutConstraintsArr = fbLoginButton.constraints
// Iterate over array and test constraints until we find the correct one:
for lc in layoutConstraintsArr { // or attribute is NSLayoutAttributeHeight etc.
if ( lc.constant == 28 ){
// Then disable it...
lc.active = false
break
}
}当我有机会测试上面的内容或者找到更好的解决方案时,我会更新答案。
发布于 2017-11-19 22:20:25
您可以通过简单地覆盖facebook按钮来方便地实现这一点。
斯威夫特
class FacebookButton: FBSDKLoginButton {
override func updateConstraints() {
// deactivate height constraints added by the facebook sdk (we'll force our own instrinsic height)
for contraint in constraints {
if contraint.firstAttribute == .height, contraint.constant < standardButtonHeight {
// deactivate this constraint
contraint.isActive = false
}
}
super.updateConstraints()
}
override var intrinsicContentSize: CGSize {
return CGSize(width: UIViewNoIntrinsicMetric, height: standardButtonHeight)
}
override func imageRect(forContentRect contentRect: CGRect) -> CGRect {
let logoSize: CGFloat = 24.0
let centerY = contentRect.midY
let y: CGFloat = centerY - (logoSize / 2.0)
return CGRect(x: y, y: y, width: logoSize, height: logoSize)
}
override func titleRect(forContentRect contentRect: CGRect) -> CGRect {
if isHidden || bounds.isEmpty {
return .zero
}
let imageRect = self.imageRect(forContentRect: contentRect)
let titleX = imageRect.maxX
let titleRect = CGRect(x: titleX, y: 0, width: contentRect.width - titleX - titleX, height: contentRect.height)
return titleRect
}
}在此代码示例中,standardButtonHeight是一个定义的常量,具有所需的按钮高度。
还请注意,24.0的徽标大小与SDK4.18版本中使用的大小相同。
发布于 2017-05-11 12:57:50
目前,Facebook按钮只有一个约束,即高度约束,您只需删除按钮的所有约束并添加您的约束即可。
facebookSignInButton.removeConstraints(facebookSignInButton.constraints)但当然,这种情况在未来可能会改变,您可能会删除不想要的约束。也许一个更好的解决方案是只删除这个有问题的约束。
if let facebookButtonHeightConstraint = facebookSignInButton.constraints.first(where: { $0.firstAttribute == .height }) {
facebookSignInButton.removeConstraint(facebookButtonHeightConstraint)
}https://stackoverflow.com/questions/42002346
复制相似问题