问题
How can I make a button's title at bottom and centered programmatically?
回答1:
Subclass NSButtonCell
and override drawTitle:withFrame:inView:(drawTitle(_,withFrame,inView)
in swift) to draw the title centered by manipulating frame
parameter for example, or draw the title by yourself. Then set your button's cell class to your subclass.
Or place NSTextField
over your button, set constraints to anchor the bottomcenter of the button and set its text to whatever you want, and keep your buttons title empty.
Unfortunately, there is no contentHorizontalAlignment
property, like in iOS, so you have to solve it with subclass or a different UI composing.
来源:https://stackoverflow.com/questions/32424770/how-to-make-nsbutton-title-at-bottom-and-centered