NSCollectionView は色々カスタムできるようなのでとやってみたけど。。。。。
いくら探してもチュートリアル Interface Builder しか出てこない。
しかもボコボコ落ちる、無意味なクラッシュレポートを Apple に沢山送ったよ。
もうあきらめて普通の NSView として使うことにするよ。
ということで。
NSView に文字列を表示したい。
[Objective-C]NSAttributedStringの背景色あたりの話|杏z 学習帳(旧)
NSMutableAttributedString というトンデモネェものがあるようだ。
筆者の用途では継承元の NSAttributedString で十分そう。
てか UIColor なの?
PyObjC には UIKit は無いぞ、あってどうするという話だが。
NSColor で当然のようにイケた、これは Apple の解説が悪いな。
comipoli オリジナルのサムネイル文字列は赤、背景色は 66ffff で 50% 半透明。
これを再現するには。
colorWithSRGBRed:green:blue:alpha: – NSColor | Apple Developer Documentation
最大値を 1.0 にして RGBA 指定でイケるのね。
やってみる。
class ItemView(NSView):
def init(self):
objc.super(ItemView, self).init()
self.image = None
self.num = 0
return self
def drawRect_(self, rect):
NSColor.blackColor().set()
NSRectFill(rect)
if (self.image):
self.image.drawInRect_(rect)
bg_color = NSColor.colorWithSRGBRed_green_blue_alpha_(0.4, 1.0, 1.0, 0.5)
text = NSAttributedString.alloc().initWithString_attributes_(
'{}'.format(self.num + 1),
{
NSForegroundColorAttributeName: NSColor.redColor(),
NSBackgroundColorAttributeName: bg_color
})
x = rect.size.width / 2
text.drawAtPoint_(NSMakePoint(x, 0))
で
オリジナル
よし完成、といいたいけどまだ超不安定。

