Skip to content

Commit 5c127f1

Browse files
author
Pavel Mazurin
committed
More attributes for OS X
1 parent cc9cbfa commit 5c127f1

5 files changed

Lines changed: 164 additions & 7 deletions

File tree

BOString.podspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Pod::Spec.new do |s|
22
s.name = "BOString"
3-
s.version = "0.0.2"
3+
s.version = "0.0.3"
44
s.summary = "Create NSAttributedString like a boss!"
55
s.homepage = "https://github.com/kovpas/BOString"
66
s.author = { "Pavel Mazurin" => "kovpas@gmail.com" }
7-
s.source = { :git => "https://github.com/kovpas/BOString.git", :tag => "0.0.2" }
7+
s.source = { :git => "https://github.com/kovpas/BOString.git", :tag => "0.0.3" }
88
s.license = 'MIT'
99
s.source_files = 'BOString/*.{h,m}'
1010

11-
s.ios.deployment_target = '6.0' # should be fine on ios 5 and 4. Can anyone test? :)
11+
s.ios.deployment_target = '6.0' # should be fine with ios 5 and 4. Can anyone test? :)
1212
s.osx.deployment_target = '10.9' # should be fine on earlier versions. Can anyone test? :)
1313

1414
s.ios.frameworks = 'Foundation', 'UIKit'

BOString/BOStringMaker.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#if TARGET_OS_IPHONE
1313
#define BOSColor UIColor
1414
#define BOSFont UIFont
15-
#elif TARGET_OS_MAC
15+
#else
1616
#define BOSColor NSColor
1717
#define BOSFont NSFont
1818
#endif
@@ -56,4 +56,14 @@
5656
- (BOStringAttribute *(^)(id))writingDirection;
5757
- (BOStringAttribute *(^)(NSNumber *))verticalGlyphForm;
5858

59+
#if !TARGET_OS_IPHONE
60+
- (BOStringAttribute *(^)(NSNumber *))superscript;
61+
- (BOStringAttribute *(^)(NSCursor *))cursor;
62+
- (BOStringAttribute *(^)(NSString *))toolTip;
63+
- (BOStringAttribute *(^)(NSNumber *))characterShape;
64+
- (BOStringAttribute *(^)(NSGlyphInfo *))glyphInfo;
65+
- (BOStringAttribute *(^)(NSNumber *))markedClauseSegment;
66+
- (BOStringAttribute *(^)(NSTextAlternatives *))textAlternatives;
67+
#endif
68+
5969
@end

BOString/BOStringMaker.m

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,5 +357,57 @@ - (BOStringAttribute *)addAttributeWithName:(NSString *)name value:(id)value
357357
};
358358
}
359359

360+
#if !TARGET_OS_IPHONE
361+
- (BOStringAttribute *(^)(NSNumber *))superscript
362+
{
363+
return ^BOStringAttribute *(NSNumber *superscript) {
364+
return [self addAttributeWithName:NSSuperscriptAttributeName value:superscript];
365+
};
366+
}
367+
368+
- (BOStringAttribute *(^)(NSCursor *))cursor
369+
{
370+
return ^BOStringAttribute *(NSCursor *cursor) {
371+
return [self addAttributeWithName:NSCursorAttributeName value:cursor];
372+
};
373+
}
374+
375+
- (BOStringAttribute *(^)(NSString *))toolTip
376+
{
377+
return ^BOStringAttribute *(NSString *toolTip) {
378+
return [self addAttributeWithName:NSToolTipAttributeName value:toolTip];
379+
};
380+
}
381+
382+
- (BOStringAttribute *(^)(NSNumber *))characterShape
383+
{
384+
return ^BOStringAttribute *(NSNumber *characterShape) {
385+
return [self addAttributeWithName:NSCharacterShapeAttributeName value:characterShape];
386+
};
387+
}
388+
389+
- (BOStringAttribute *(^)(NSGlyphInfo *))glyphInfo
390+
{
391+
return ^BOStringAttribute *(NSGlyphInfo *glyphInfo) {
392+
return [self addAttributeWithName:NSGlyphInfoAttributeName value:glyphInfo];
393+
};
394+
}
395+
396+
- (BOStringAttribute *(^)(NSNumber *))markedClauseSegment
397+
{
398+
return ^BOStringAttribute *(NSNumber *markedClauseSegment) {
399+
return [self addAttributeWithName:NSMarkedClauseSegmentAttributeName value:markedClauseSegment];
400+
};
401+
}
402+
403+
- (BOStringAttribute *(^)(NSTextAlternatives *))textAlternatives
404+
{
405+
return ^BOStringAttribute *(NSTextAlternatives *textAlternatives) {
406+
return [self addAttributeWithName:NSTextAlternativesAttributeName value:textAlternatives];
407+
};
408+
}
409+
410+
#endif
411+
360412

361413
@end

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ underlineStyle;
7171
strokeColor;
7272
strokeWidth;
7373
shadow;
74-
textEffect;
74+
textEffect; // iOS only
7575
attachment;
7676
link;
7777
baselineOffset;
@@ -81,6 +81,13 @@ obliqueness;
8181
expansion;
8282
writingDirection;
8383
verticalGlyphForm;
84+
superscript; // OS X only
85+
cursor; // OS X only
86+
toolTip; // OS X only
87+
characterShape; // OS X only
88+
glyphInfo; // OS X only
89+
markedClauseSegment; // OS X only
90+
textAlternatives; // OS X only
8491
````
8592

8693
While making a string you can specify ranges for attributes either with a block-based syntax as in the example above:
@@ -123,6 +130,12 @@ NSAttributedString *result = [@"This is a string" makeString:^(BOStringMaker *ma
123130
}];
124131
````
125132

133+
Supported platforms
134+
=======
135+
136+
- **iOS 6.0** and later. Should work fine on iOS 4.3 and later, but I haven't had a chance to test it.
137+
- **OS X 10.9** and later. Should work fine on OS X 10.5 and later, but I haven't had a chance to test it.
138+
126139
Installation
127140
=======
128141

Tests/BOStringTests.m

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#if TARGET_OS_IPHONE
1616
#define IS_IOS7 ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] == NSOrderedDescending)
17-
#elif TARGET_OS_MAC
17+
#else
1818
#define IS_IOS7 YES
1919
#endif
2020

@@ -59,7 +59,7 @@
5959
NSMutableParagraphStyle *testParagraphStyle = [[NSMutableParagraphStyle alloc] init];
6060
#if TARGET_OS_IPHONE
6161
testParagraphStyle.alignment = NSTextAlignmentCenter;
62-
#elif TARGET_OS_MAC
62+
#else
6363
testParagraphStyle.alignment = NSCenterTextAlignment;
6464
#endif
6565
testParagraphStyle.lineBreakMode = NSLineBreakByTruncatingMiddle;
@@ -316,6 +316,88 @@
316316

317317
expect(result).to.equal(testAttributedString);
318318
});
319+
#if !TARGET_OS_IPHONE
320+
it( @"superscript should change", ^{
321+
NSNumber *testSuperscript = @(2);
322+
NSAttributedString *result = [_testString makeString:^(BOStringMaker *make) {
323+
make.superscript(testSuperscript);
324+
}];
325+
326+
NSAttributedString *testAttributedString = [[NSAttributedString alloc] initWithString:_testString attributes:@{NSSuperscriptAttributeName: testSuperscript}];
327+
328+
expect(result).to.equal(testAttributedString);
329+
});
330+
331+
it( @"cursor should change", ^{
332+
NSCursor *testCursor = [NSCursor resizeRightCursor];
333+
NSAttributedString *result = [_testString makeString:^(BOStringMaker *make) {
334+
make.cursor(testCursor);
335+
}];
336+
337+
NSAttributedString *testAttributedString = [[NSAttributedString alloc] initWithString:_testString attributes:@{NSCursorAttributeName: testCursor}];
338+
339+
expect(result).to.equal(testAttributedString);
340+
});
341+
342+
it( @"toolTip should change", ^{
343+
NSString *testToolTip = @"Test tooltip";
344+
NSAttributedString *result = [_testString makeString:^(BOStringMaker *make) {
345+
make.toolTip(testToolTip);
346+
}];
347+
348+
NSAttributedString *testAttributedString = [[NSAttributedString alloc] initWithString:_testString attributes:@{NSToolTipAttributeName: testToolTip}];
349+
350+
expect(result).to.equal(testAttributedString);
351+
});
352+
353+
it( @"characterShape should change", ^{
354+
NSNumber *testCharacterShape = @(kTraditionalAltTwoSelector);
355+
NSAttributedString *result = [_testString makeString:^(BOStringMaker *make) {
356+
make.characterShape(testCharacterShape);
357+
}];
358+
359+
NSAttributedString *testAttributedString = [[NSAttributedString alloc] initWithString:_testString attributes:@{NSCharacterShapeAttributeName: testCharacterShape}];
360+
361+
expect(result).to.equal(testAttributedString);
362+
});
363+
364+
it( @"glyphInfo should change", ^{
365+
NSString* baseString = [NSString stringWithFormat:@"%C", (unichar)0xFFFD];
366+
NSGlyphInfo* testGlyphInfo = [NSGlyphInfo glyphInfoWithGlyphName:@"copyright"
367+
forFont:[NSFont systemFontOfSize:10]
368+
baseString:baseString];
369+
NSAttributedString *result = [_testString makeString:^(BOStringMaker *make) {
370+
make.glyphInfo(testGlyphInfo);
371+
}];
372+
373+
NSAttributedString *testAttributedString = [[NSAttributedString alloc] initWithString:_testString attributes:@{NSGlyphInfoAttributeName: testGlyphInfo}];
374+
375+
expect(result).to.equal(testAttributedString);
376+
});
377+
378+
it( @"markedClauseSegment should change", ^{
379+
NSNumber *testMarkedClauseSegment = @(1);
380+
NSAttributedString *result = [_testString makeString:^(BOStringMaker *make) {
381+
make.markedClauseSegment(testMarkedClauseSegment);
382+
}];
383+
384+
NSAttributedString *testAttributedString = [[NSAttributedString alloc] initWithString:_testString attributes:@{NSMarkedClauseSegmentAttributeName: testMarkedClauseSegment}];
385+
386+
expect(result).to.equal(testAttributedString);
387+
});
388+
389+
it( @"textAlternatives should change", ^{
390+
NSTextAlternatives *testTextAlternatives = [[NSTextAlternatives alloc] initWithPrimaryString:_testString alternativeStrings:@[@"Alternative 1", @"Alternative 2"]];
391+
NSAttributedString *result = [_testString makeString:^(BOStringMaker *make) {
392+
make.textAlternatives(testTextAlternatives);
393+
}];
394+
395+
NSAttributedString *testAttributedString = [[NSAttributedString alloc] initWithString:_testString attributes:@{NSTextAlternativesAttributeName: testTextAlternatives}];
396+
397+
expect(result).to.equal(testAttributedString);
398+
});
399+
400+
#endif
319401
});
320402

321403
describe(@"Ranged attributes", ^{

0 commit comments

Comments
 (0)