How to make NSButton title at bottom and centered?

2019-07-15 02:04发布

How can I make a button's title at bottom and centered programmatically?

1条回答
祖国的老花朵
2楼-- · 2019-07-15 02:32

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.

查看更多
登录 后发表回答