I want use the object - NSTextField
to display an image. But the result isn't correct.
the image size is 32x32.
my code like this:
class ViewController: NSViewController {
var text: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
text = NSTextField(frame: NSRect(origin: CGPoint(x: 200, y: 200), size: CGSize(width: 32, height: 32)))
text.backgroundColor = .clear
text.isBordered = true
text.isEditable = false
let attachment = NSTextAttachment()
attachment.image = NSImage(named: NSImage.Name(rawValue: "Group_8"))
attachment.bounds = NSRect(origin: .zero, size: (attachment.image?.size)!)
let string = NSAttributedString(attachment: attachment)
text.attributedStringValue = string
view.addSubview(text)
// Do any additional setup after loading the view.
}
The final displayed like this:
Why white blank areas appear?