Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OS X Support #22

Open
Gerst20051 opened this issue Feb 9, 2016 · 1 comment
Open

OS X Support #22

Gerst20051 opened this issue Feb 9, 2016 · 1 comment

Comments

@Gerst20051
Copy link

Any reason this doesn't support OS X apps?

@snaill
Copy link

snaill commented Sep 2, 2016

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)
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants