Font-Awesome-Swift icon indicating copy to clipboard operation
Font-Awesome-Swift copied to clipboard

OS X Support

Open Gerst20051 opened this issue 8 years ago • 1 comments

Any reason this doesn't support OS X apps?

Gerst20051 avatar Feb 09 '16 18:02 Gerst20051

import Cocoa

public extension NSControl {

func FAFontSize() -> CGFloat {
    switch controlSize {
    case .MiniControlSize:
        return 8
    default:
        return 15
    }
}

}

public extension NSMenuItem {

func setFAIcon(icon: FAType, controlSize: NSControlSize) {

    FontLoader.loadFontIfNeeded()
    let font = NSFont(name: FAStruct.FontName, size: controlSize == .MiniControlSize ? 8 : 15)
    assert(font != nil, FAStruct.ErrorAnnounce)

    let attrStr = NSMutableAttributedString(string: icon.text!, attributes: [NSFontAttributeName: font!])
    self.attributedTitle = attrStr
}

}

public extension NSButton {

/**
 To set an icon, use i.e. `buttonName.setFAIcon(FAType.FAGithub)`
 */
func setFAIcon(icon: FAType) {

    FontLoader.loadFontIfNeeded()
    let font = NSFont(name: FAStruct.FontName, size: FAFontSize())
    assert(font != nil, FAStruct.ErrorAnnounce)

    self.title = icon.text!
    (self.cell as! NSButtonCell).font = font!
}

}

public extension NSSegmentedControl {

public func setFAIcon(icon: FAType, forSegmentAtIndex segment: Int) {

    FontLoader.loadFontIfNeeded()
    let font = NSFont(name: FAStruct.FontName, size: FAFontSize())
    assert(font != nil, FAStruct.ErrorAnnounce)
    self.font = font
    setLabel(icon.text!, forSegment: segment)
}

}

snaill avatar Sep 02 '16 08:09 snaill