[英]NSAttributedString size() method returns incorrect width
我創建了一個自定義NSButtonCell
子類,該子類允許自定義按鈕內容之間的填充。 在我的實現中(完整的源代碼可以在GitHub上找到 ),我重寫titleRect(forBounds :)來放置按鈕標題:
var titleSize: NSSize {
return NSSize(width: ceil(attributedTitle.size().width),
height: ceil(attributedTitle.size().height))
}
override func titleRect(forBounds rect: NSRect) -> NSRect {
return CGRect(x: paddingLeft,
y: rect.height / 2 - titleSize.height / 2,
width: titleSize.width,
height: titleSize.height)
}
結果看起來不太好:
我也嘗試使用boundingRect(with:options:context :)來獲取大小,但是得到了相同的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.