How to make NSButton title at bottom and centered?

混江龙づ霸主 提交于 2019-12-12 17:53:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!