Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions RTLabelProject/Classes/RTLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ typedef enum
@property (nonatomic, copy) NSString *text;
@property (nonatomic, copy) NSString *tagLabel;
@property (nonatomic) NSMutableDictionary *attributes;
@property (nonatomic, assign) int position;
@property (nonatomic, assign) NSInteger position;

- (id)initWithString:(NSString*)aText tag:(NSString*)aTagLabel attributes:(NSMutableDictionary*)theAttributes;
+ (id)componentWithString:(NSString*)aText tag:(NSString*)aTagLabel attributes:(NSMutableDictionary*)theAttributes;
- (id)initWithTag:(NSString*)aTagLabel position:(int)_position attributes:(NSMutableDictionary*)_attributes;
+ (id)componentWithTag:(NSString*)aTagLabel position:(int)aPosition attributes:(NSMutableDictionary*)theAttributes;
- (id)initWithTag:(NSString*)aTagLabel position:(NSInteger)_position attributes:(NSMutableDictionary*)_attributes;
+ (id)componentWithTag:(NSString*)aTagLabel position:(NSInteger)aPosition attributes:(NSMutableDictionary*)theAttributes;

@end

Expand All @@ -85,7 +85,7 @@ typedef enum
@property (nonatomic, strong) UIFont *font;
@property (nonatomic, strong) NSDictionary *linkAttributes;
@property (nonatomic, strong) NSDictionary *selectedLinkAttributes;
@property (nonatomic, unsafe_unretained) id<RTLabelDelegate> delegate;
@property (nonatomic, weak) id<RTLabelDelegate> delegate;
@property (nonatomic, copy) NSString *paragraphReplacement;
@property (nonatomic, strong) NSMutableArray *textComponents, *highlightedTextComponents;
@property (nonatomic, assign) RTTextAlignment textAlignment;
Expand Down
56 changes: 28 additions & 28 deletions RTLabelProject/Classes/RTLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ + (id)componentWithString:(NSString*)aText tag:(NSString*)aTagLabel attributes:(
return [[self alloc] initWithString:aText tag:aTagLabel attributes:theAttributes];
}

- (id)initWithTag:(NSString*)aTagLabel position:(int)aPosition attributes:(NSMutableDictionary*)theAttributes
- (id)initWithTag:(NSString*)aTagLabel position:(NSInteger)aPosition attributes:(NSMutableDictionary*)theAttributes
{
self = [super init];
if (self) {
Expand All @@ -74,7 +74,7 @@ - (id)initWithTag:(NSString*)aTagLabel position:(int)aPosition attributes:(NSMut
return self;
}

+(id)componentWithTag:(NSString*)aTagLabel position:(int)aPosition attributes:(NSMutableDictionary*)theAttributes
+(id)componentWithTag:(NSString*)aTagLabel position:(NSInteger)aPosition attributes:(NSMutableDictionary*)theAttributes
{
return [[self alloc] initWithTag:aTagLabel position:aPosition attributes:theAttributes];
}
Expand All @@ -83,7 +83,7 @@ - (NSString*)description
{
NSMutableString *desc = [NSMutableString string];
[desc appendFormat:@"text: %@", self.text];
[desc appendFormat:@", position: %i", self.position];
[desc appendFormat:@", position: %ld",(long) self.position];
if (self.tagLabel) [desc appendFormat:@", tag: %@", self.tagLabel];
if (self.attributes) [desc appendFormat:@", attributes: %@", self.attributes];
return desc;
Expand Down Expand Up @@ -114,15 +114,15 @@ - (void)render;
#pragma mark -
#pragma mark styling

- (void)applyItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyBoldStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyBoldItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyColor:(NSString*)value toText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applySingleUnderlineText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyDoubleUnderlineText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyUnderlineColor:(NSString*)value toText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyFontAttributes:(NSDictionary*)attributes toText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length;
- (void)applyParagraphStyleToText:(CFMutableAttributedStringRef)text attributes:(NSMutableDictionary*)attributes atPosition:(int)position withLength:(int)length;
- (void)applyItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length;
- (void)applyBoldStyleToText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length;
- (void)applyBoldItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length;
- (void)applyColor:(NSString*)value toText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length;
- (void)applySingleUnderlineText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length;
- (void)applyDoubleUnderlineText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length;
- (void)applyUnderlineColor:(NSString*)value toText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length;
- (void)applyFontAttributes:(NSDictionary*)attributes toText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length;
- (void)applyParagraphStyleToText:(CFMutableAttributedStringRef)text attributes:(NSMutableDictionary*)attributes atPosition:(NSInteger)position withLength:(NSInteger)length;
@end

@implementation RTLabel
Expand Down Expand Up @@ -232,7 +232,7 @@ - (void)render

for (RTLabelComponent *component in textComponents)
{
int index = [textComponents indexOfObject:component];
NSInteger index = [textComponents indexOfObject:component];
component.componentIndex = index;

if ([component.tagLabel caseInsensitiveCompare:@"i"] == NSOrderedSame)
Expand Down Expand Up @@ -393,7 +393,7 @@ - (void)render
#pragma mark -
#pragma mark styling

- (void)applyParagraphStyleToText:(CFMutableAttributedStringRef)text attributes:(NSMutableDictionary*)attributes atPosition:(int)position withLength:(int)length
- (void)applyParagraphStyleToText:(CFMutableAttributedStringRef)text attributes:(NSMutableDictionary*)attributes atPosition:(NSInteger)position withLength:(NSInteger)length
{
CFMutableDictionaryRef styleDict = ( CFDictionaryCreateMutable( (0), 0, (0), (0) ) );

Expand Down Expand Up @@ -494,7 +494,7 @@ - (void)applyParagraphStyleToText:(CFMutableAttributedStringRef)text attributes:
CFRelease(styleDict);
}

- (void)applyCenterStyleToText:(CFMutableAttributedStringRef)text attributes:(NSMutableDictionary*)attributes atPosition:(int)position withLength:(int)length
- (void)applyCenterStyleToText:(CFMutableAttributedStringRef)text attributes:(NSMutableDictionary*)attributes atPosition:(NSInteger)position withLength:(NSInteger)length
{
CFMutableDictionaryRef styleDict = ( CFDictionaryCreateMutable( (0), 0, (0), (0) ) );

Expand Down Expand Up @@ -539,17 +539,17 @@ - (void)applyCenterStyleToText:(CFMutableAttributedStringRef)text attributes:(NS
CFRelease(styleDict);
}

- (void)applySingleUnderlineText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length
- (void)applySingleUnderlineText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length
{
CFAttributedStringSetAttribute(text, CFRangeMake(position, length), kCTUnderlineStyleAttributeName, (__bridge CFNumberRef)[NSNumber numberWithInt:kCTUnderlineStyleSingle]);
}

- (void)applyDoubleUnderlineText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length
- (void)applyDoubleUnderlineText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length
{
CFAttributedStringSetAttribute(text, CFRangeMake(position, length), kCTUnderlineStyleAttributeName, (__bridge CFNumberRef)[NSNumber numberWithInt:kCTUnderlineStyleDouble]);
}

- (void)applyItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length
- (void)applyItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length
{
CFTypeRef actualFontRef = CFAttributedStringGetAttribute(text, position, kCTFontAttributeName, NULL);
CTFontRef italicFontRef = CTFontCreateCopyWithSymbolicTraits(actualFontRef, 0.0, NULL, kCTFontItalicTrait, kCTFontItalicTrait);
Expand All @@ -562,7 +562,7 @@ - (void)applyItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(in
CFRelease(italicFontRef);
}

- (void)applyFontAttributes:(NSDictionary*)attributes toText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length
- (void)applyFontAttributes:(NSDictionary*)attributes toText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length
{
for (NSString *key in attributes)
{
Expand Down Expand Up @@ -631,7 +631,7 @@ - (void)applyFontAttributes:(NSDictionary*)attributes toText:(CFMutableAttribute
}
}

- (void)applyBoldStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length
- (void)applyBoldStyleToText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length
{
CFTypeRef actualFontRef = CFAttributedStringGetAttribute(text, position, kCTFontAttributeName, NULL);
CTFontRef boldFontRef = CTFontCreateCopyWithSymbolicTraits(actualFontRef, 0.0, NULL, kCTFontBoldTrait, kCTFontBoldTrait);
Expand All @@ -644,7 +644,7 @@ - (void)applyBoldStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)
CFRelease(boldFontRef);
}

- (void)applyBoldItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length
- (void)applyBoldItalicStyleToText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length
{
CFTypeRef actualFontRef = CFAttributedStringGetAttribute(text, position, kCTFontAttributeName, NULL);
CTFontRef boldItalicFontRef = CTFontCreateCopyWithSymbolicTraits(actualFontRef, 0.0, NULL, kCTFontBoldTrait | kCTFontItalicTrait , kCTFontBoldTrait | kCTFontItalicTrait);
Expand All @@ -661,7 +661,7 @@ - (void)applyBoldItalicStyleToText:(CFMutableAttributedStringRef)text atPosition

}

- (void)applyColor:(NSString*)value toText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length
- (void)applyColor:(NSString*)value toText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length
{

if ([value rangeOfString:@"#"].location==0)
Expand All @@ -686,7 +686,7 @@ - (void)applyColor:(NSString*)value toText:(CFMutableAttributedStringRef)text at
}
}

- (void)applyUnderlineColor:(NSString*)value toText:(CFMutableAttributedStringRef)text atPosition:(int)position withLength:(int)length
- (void)applyUnderlineColor:(NSString*)value toText:(CFMutableAttributedStringRef)text atPosition:(NSInteger)position withLength:(NSInteger)length
{

value = [value stringByReplacingOccurrencesOfString:@"'" withString:@""];
Expand Down Expand Up @@ -865,15 +865,15 @@ + (RTLabelExtractedComponent*)extractTextStyleFromText:(NSString*)data paragraph

NSMutableArray *components = [NSMutableArray array];

int last_position = 0;
NSInteger last_position = 0;
scanner = [NSScanner scannerWithString:data];
while (![scanner isAtEnd])
{
[scanner scanUpToString:@"<" intoString:NULL];
[scanner scanUpToString:@">" intoString:&text];

NSString *delimiter = [NSString stringWithFormat:@"%@>", text];
int position = [data rangeOfString:delimiter].location;
NSInteger position = [data rangeOfString:delimiter].location;
if (position!=NSNotFound)
{
if ([delimiter rangeOfString:@"<p"].location==0)
Expand All @@ -895,7 +895,7 @@ + (RTLabelExtractedComponent*)extractTextStyleFromText:(NSString*)data paragraph
tag = [text substringFromIndex:2];
if (position!=NSNotFound)
{
for (int i=[components count]-1; i>=0; i--)
for (NSInteger i=[components count]-1; i>=0; i--)
{
RTLabelComponent *component = [components objectAtIndex:i];
if (component.text==nil && [component.tagLabel isEqualToString:tag])
Expand Down Expand Up @@ -956,7 +956,7 @@ - (void)parse:(NSString *)data valid_tags:(NSArray *)valid_tags
scanner = [NSScanner scannerWithString:data];
NSMutableDictionary *lastAttributes = nil;

int last_position = 0;
NSInteger last_position = 0;
while([scanner isAtEnd] == NO)
{
//find start of tag
Expand Down Expand Up @@ -995,7 +995,7 @@ - (void)parse:(NSString *)data valid_tags:(NSArray *)valid_tags
if([valid_tags containsObject:tag] == NO)
{
NSString *delimiter = [NSString stringWithFormat:@"%@>", text];
int position = [data rangeOfString:delimiter].location;
NSInteger position = [data rangeOfString:delimiter].location;
BOOL isEnd = [delimiter rangeOfString:@"</"].location!=NSNotFound;
if (position!=NSNotFound)
{
Expand Down