UIButton是剪切下行器(如小写“g”)

时间:2016-01-27 16:55:17

标签: uibutton tvos

我正在构建一个使用UIButton中的自定义字体的tvOS应用。

我注意到.Normal.Focused UIControlState中的descenders被剪裁了,如下图所示:

enter image description here

我尝试调整contentEdgeInsetstitleEdgeInsets,但都没有修正错误。

1 个答案:

答案 0 :(得分:1)

当然,在我写这个问题时,我记得答案了!

一个解决方案:子类UIButton并覆盖方法titleRectForContentRectcontentRectForBounds,如下所示:

/// 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

瞧!没有更多剪裁的下降器: enter image description here