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:

enter image description here

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 

voila! no more clipped descenders: enter image description here


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -