tvos - UIButton is clipping descenders (like lowercase "g") -
i'm building tvos app uses custom font in uibutton
.
i've noticed descenders getting clipped in both .normal
, .focused
uicontrolstate
, can see in image:
i've tried adjusting contentedgeinsets
, titleedgeinsets
, neither fixed error.
of course, i'm writing question, remembered answer!
one solution: subclass uibutton
, override methods titlerectforcontentrect
, contentrectforbounds
, so:
/// subclass of uibutton uses full bounds of button label (so 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 } }
the other remaining bit: center title label's text:
let button = fullframetitlebutton(type: .system) button.titlelabel?.textalignment = .center
Comments
Post a Comment