如何使NSButton标题位于底部和居中? [英] How to make NSButton title at bottom and centered?

查看:245
本文介绍了如何使NSButton标题位于底部和居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使按钮的标题位于底部并以编程方式居中?

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

推荐答案

子类 NSButtonCell 并覆盖 drawTitle:withFrame:inView: drawTitle(_,withFrame,inView )迅速绘制),例如,通过操纵 frame 参数绘制居中的标题,或者自己绘制标题。然后将按钮的单元格类设置为子类。

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.

或在按钮上放置 NSTextField ,设置约束以锚定

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.

不幸的是,没有 contentHorizo​​ntalAlignment c $ c>属性,就像在iOS中一样,因此您必须使用子类或其他UI组合来解决它。

Unfortunately, there is no contentHorizontalAlignment property, like in iOS, so you have to solve it with subclass or a different UI composing.

这篇关于如何使NSButton标题位于底部和居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆