Giter Site home page Giter Site logo

chipjarred / customtooltip Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 4.0 287 KB

Easily add custom tool tips with arbitrary content to your AppKit project!

License: MIT License

Swift 100.00%
macos macosx macapp appkit swift cocoa swiftpackage nsview tooltip

customtooltip's Introduction

CustomToolTip

CustomToolTip is a Swift Package for macOS Cocoa applications that lets you add tool tips that can use any kind of NSView for their content without having to subclass or wrap your existing views. That means it can be easily incorporated into an existing project.

Screenshot

Project Set Up

CustomToolTip provides an extension on NSView that handles the rest. You can focus on creating your tool tip content and attach it to your views with the customToolTip property that the extension adds to NSView.

You don't need to subclass anything. You don't need to nest views in a special tool tip view. You don't even need to change anything in storyboards.

How to add custom tool tips

In the source files where you want to add custom tool tips,

import CustomToolTip

Then adding a tool tip is as easy as

myControl.customToolTip = myCustomTipContentView

where myControl, is the view to which you want to attach a custom tool tip, and myCustomTipContentView is any NSView you want to use as the tool tip's content.

The only technical requirement for your tool tip view is that its frame size should be properly set before adding it, as the tool tip will adjust its size according to your content view's frame.

There are design considerations for your tool tip content, but those will largely depend on taste, the look and feel of your app, and current thought on good design. The only suggestions I'll make are to keep your tool tips relatively small, and avoid using any view in them that looks like the user should interact with it, because... it's a tool tip. It will disappear when the user moves the mouse.

You can specify the margins between your custom tool tip content view, and the tool tip's window frame:

myControl.customToolTipMargins = CGSize(width: 5, height: 5)

By default CustomToolTip uses the current system window background color for the tool tip's background, but you can use any color you like:

myControl.customToolTipBackgroundColor = NSColor.blue

You can also set the default values to use when you don't specify them per view:

CustomToolTip.defaultMargins = CGSize(width: 2, height: 2)
CustomToolTip.defaultBackColor = .controlColor

Conveniences

For some especially common cases CustomToolTip provides convenience methods that will make the view for you.

If you just want to add a text tool tip using a specific font, you can do it like this:

myControl.addCustomToolTip(from: "This is my tool tip", with: NSFont(name: "Chalkboard", size: 20))

If you have an NSAttributedString you'd like to display in the tool tip, you can use that:

myControl.addCustomToolTip(from: myAttributedString)

To use an NSImage as the content:

myControl.addCustomToolTip(from: myToolTipImage, scaling: .toFit(width: 50, height: 50))

customtooltip's People

Contributors

chipjarred avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

customtooltip's Issues

Error resolving CustomToolTip - 'customtooltip' depends on an unstable-version package 'swizzlehelper'

Receiving the following error when trying to resolve CustomToolTip via SPM:

Dependencies could not be resolved because package 'customtooltip' is required using a stable-version but 'customtooltip' depends on an unstable-version package 'swizzlehelper' and root depends on 'CustomToolTip' 1.0.0..<2.0.0.
'CustomToolTip' {1.0.0..<1.0.2, 1.0.3..<2.0.0} cannot be used because package 'customtooltip' is required using a stable-version but 'customtooltip' depends on an unstable-version package 'swizzlehelper' and package 'customtooltip' is required using a stable-version but 'customtooltip' depends on an unstable-version package 'swizzlehelper'.
'CustomToolTip' {1.0.0, 1.0.3..<2.0.0} cannot be used because no versions of 'CustomToolTip' match the requirement 1.0.3..<2.0.0 and package 'customtooltip' is required using a stable-version but 'customtooltip' depends on an unstable-version package 'swizzlehelper'.

I believe this is because we're referencing .branch("main") in https://github.com/chipjarred/CustomToolTip/blob/main/Package.swift#L18. Is there a reason not to change this to the https://github.com/chipjarred/SwizzleHelper/releases/tag/1.0.0 tag?

In the meantime, I'll just add CustomToolTip using the main branch instead of using the latest tag. Thanks in advance for the help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.