0
我正在構建使用自定義字體UIButton
的tvOS應用程序。UIButton是削減下降(如小寫「g」)
我注意到descenders都在.Normal
和.Focused
UIControlState
都被限幅,你可以在此圖像中看到:
我試着調整contentEdgeInsets
和titleEdgeInsets
,但也修復了錯誤。
我正在構建使用自定義字體UIButton
的tvOS應用程序。UIButton是削減下降(如小寫「g」)
我注意到descenders都在.Normal
和.Focused
UIControlState
都被限幅,你可以在此圖像中看到:
我試着調整contentEdgeInsets
和titleEdgeInsets
,但也修復了錯誤。
當然,在我寫這個問題時,我想起了答案!
一個解決方案:子類UIButton
和覆蓋的方法titleRectForContentRect
和contentRectForBounds
,像這樣:
/// A subclass of UIButton that uses the full bounds of the button for the label (so that text isn't clipped)
public class FullFrameTitleButton: UIButton {
override public func titleRectForContentRect(contentRect: CGRect) -> CGRect {
return contentRect
}
override public func contentRectForBounds(bounds: CGRect) -> CGRect {
return bounds
}
}
的唯一其他剩餘位:中心標題標籤的文本:
let button = FullFrameTitleButton(type: .System)
button.titleLabel?.textAlignment = .Center