Sha256: 30d05b55aa8ba14422ed5cd73148f7d26cfb2c6aa399b2584f9b2180b6b22348
Contents?: true
Size: 1.13 KB
Versions: 20
Compression:
Stored size: 1.13 KB
Contents
class NSString # @return [NSImage] def nsimage NSImage.imageNamed(self).tap do |retval| NSLog("No image named #{self}") unless retval end end # @return [NSFont] def nsfont(size=nil) size ||= NSFont.systemFontSize NSFont.fontWithName(self, size: size) end # @param font [NSFont] Optional, defaults to NSFont.systemFontOfSize(NSFont.systemFontSize) # @return [NSLabel] def nslabel(font=nil) font ||= :system.nsfont(NSFont.labelFontSize) size = self.sizeWithAttributes({ NSFontAttributeName => font }) label = NSTextField.alloc.initWithFrame([[0, 0], size]) label.bezeled = false label.drawsBackground = false label.editable = false label.selectable = false label.stringValue = self label.font = font return label end # @return [NSImageView] def nsimageview image = NSImage.imageNamed(self) unless image NSLog("No image named #{self}") end image_view = NSImageView.alloc.init image_view.image = image frame = image_view.frame frame.size = image_view.intrinsicContentSize image_view.frame = frame return image_view end end
Version data entries
20 entries across 20 versions & 1 rubygems