Skip to content

Commit 77d0300

Browse files
committed
Add toolTip extension.
1 parent d2f0e3d commit 77d0300

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

Attributed.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
43C994161BE3DE8E00CF90DD /* AttributedStringConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C993F01BE3C9CE00CF90DD /* AttributedStringConvertibleTests.swift */; };
4646
43CDB1E41BE3FE6800440B11 /* AttributedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43C993D71BE3B9C700CF90DD /* AttributedTests.swift */; };
4747
43D5EA131BFF5FE200E48BD6 /* NSCursor+Attributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43D5EA121BFF5FE200E48BD6 /* NSCursor+Attributes.swift */; };
48+
43D5EA151C0026A400E48BD6 /* String+Attributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43D5EA141C0026A400E48BD6 /* String+Attributes.swift */; };
4849
/* End PBXBuildFile section */
4950

5051
/* Begin PBXContainerItemProxy section */
@@ -90,6 +91,7 @@
9091
43C993F91BE3DDF800CF90DD /* Attributed.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Attributed.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9192
43C994021BE3DDF900CF90DD /* Attributed-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Attributed-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
9293
43D5EA121BFF5FE200E48BD6 /* NSCursor+Attributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSCursor+Attributes.swift"; sourceTree = "<group>"; };
94+
43D5EA141C0026A400E48BD6 /* String+Attributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Attributes.swift"; sourceTree = "<group>"; };
9395
/* End PBXFileReference section */
9496

9597
/* Begin PBXFrameworksBuildPhase section */
@@ -160,6 +162,7 @@
160162
43C752391BEA601900F928E5 /* NSTextAttachment+Attributes.swift */,
161163
434DBBC71BEC39FA00C11F09 /* NSUnderlineStyle+Attributes.swift */,
162164
433A9C0D1BECF169009A3919 /* SequenceType+Join.swift */,
165+
43D5EA141C0026A400E48BD6 /* String+Attributes.swift */,
163166
);
164167
name = Extensions;
165168
sourceTree = "<group>";
@@ -389,6 +392,7 @@
389392
43C993E31BE3BAA100CF90DD /* Functions.swift in Sources */,
390393
43C993ED1BE3C2E800CF90DD /* Ligature.swift in Sources */,
391394
43C752311BEA525100F928E5 /* ColorType+Attributes.swift in Sources */,
395+
43D5EA151C0026A400E48BD6 /* String+Attributes.swift in Sources */,
392396
43C993E71BE3BB0B00CF90DD /* AttributedStringConvertible.swift in Sources */,
393397
43C752371BEA5F0A00F928E5 /* FontType+Attributes.swift in Sources */,
394398
43C7523A1BEA601900F928E5 /* NSTextAttachment+Attributes.swift in Sources */,

Attributed/String+Attributes.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Attributed
2+
// Written in 2015 by Nate Stedman <[email protected]>
3+
//
4+
// To the extent possible under law, the author(s) have dedicated all copyright and
5+
// related and neighboring rights to this software to the public domain worldwide.
6+
// This software is distributed without any warranty.
7+
//
8+
// You should have received a copy of the CC0 Public Domain Dedication along with
9+
// this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
10+
11+
#if os(OSX)
12+
import AppKit
13+
14+
extension String
15+
{
16+
// MARK: - Tooltip
17+
18+
/**
19+
Applies a tooltip attribute to the enclosed attributed strings.
20+
21+
The tooltip will not override a tooltip set deeper in the hierarchy.
22+
23+
- parameter strings: The attributed strings to apply the tooltip to.
24+
*/
25+
public func toolTipAttribute(strings: AttributedStringConvertible...) -> AttributedStringConvertible
26+
{
27+
return Attributed.attribute(NSToolTipAttributeName, self, strings)
28+
}
29+
30+
/**
31+
Applies a tooltip attribute to the enclosed attributed strings.
32+
33+
The tooltip will not override a tooltip set deeper in the hierarchy.
34+
35+
- parameter strings: The attributed strings to apply the tooltip to.
36+
*/
37+
public func toolTipAttribute(strings: [AttributedStringConvertible]) -> AttributedStringConvertible
38+
{
39+
return Attributed.attribute(NSToolTipAttributeName, self, strings)
40+
}
41+
}
42+
#endif

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ These additional framework types are extended with attribute functions:
6464
- `NSParagraphStyle`: `attribute`, which maps to `NSParagraphStyleAttributeName`.
6565
- `NSShadow`: `attribute`, which maps to `NSShadowAttributeName`.
6666
- `NSUnderlineStyle`: `attribute`, which maps to `NSUnderlineStyleAttributeName`; and `strikethroughAttribute`, which makes to `NSStrikethroughStyleAttributeName`.
67+
- `String`, on OS X only: `toolTipAttribute`, which maps to `NSToolTipAttributeName`.
6768

6869
#### Numeric Types
6970
Attributes with numeric values use the `NSNumberConvertible` protocol. The framework provides implementations for these types:

0 commit comments

Comments
 (0)