Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Modernizing Obj-C. Fixing crashing. Removing warnings for 64-bit. #50

Open
wants to merge 3 commits into from

1 participant

Commits on Dec 12, 2013
  1. @devinross
  2. @devinross
Commits on Dec 20, 2013
  1. @devinross
This page is out of date. Refresh to see the latest.
View
30 RTLabelProject/Classes/DemoTableViewController.m
@@ -61,35 +61,35 @@ - (id)initWithStyle:(UITableViewStyle)style
_dataArray = [NSMutableArray array];
NSMutableDictionary *row1 = [NSMutableDictionary dictionary];
- [row1 setObject:@"<b>bold</b> and <i>italic</i> style" forKey:@"text"];
+ row1[@"text"] = @"<b>bold</b> and <i>italic</i> style";
[self.dataArray addObject:row1];
NSMutableDictionary *row2 = [NSMutableDictionary dictionary];
- [row2 setObject:@"<font face='HelveticaNeue-CondensedBold' size=20><u color=blue>underlined</u> <uu color=red>text</uu></font>" forKey:@"text"];
+ row2[@"text"] = @"<font face='HelveticaNeue-CondensedBold' size=20><u color=blue>underlined</u> <uu color=red>text</uu></font>";
[self.dataArray addObject:row2];
NSMutableDictionary *row3 = [NSMutableDictionary dictionary];
- [row3 setObject:@"clickable link - <a href='http://store.apple.com'>link to apple store</a> <a href='http://www.google.com'>link to google</a> <a href='http://www.yahoo.com'>link to yahoo</a> <a href='https://github.com/honcheng/RTLabel'>link to RTLabel in GitHub</a> <a href='http://www.wiki.com'>link to wiki.com website</a>" forKey:@"text"];
+ row3[@"text"] = @"clickable link - <a href='http://store.apple.com'>link to apple store</a> <a href='http://www.google.com'>link to google</a> <a href='http://www.yahoo.com'>link to yahoo</a> <a href='https://github.com/honcheng/RTLabel'>link to RTLabel in GitHub</a> <a href='http://www.wiki.com'>link to wiki.com website</a>";
[self.dataArray addObject:row3];
NSMutableDictionary *row4 = [NSMutableDictionary dictionary];
- [row4 setObject:@"<font face='HelveticaNeue-CondensedBold' size=20 color='#CCFF00'>Text with</font> <font face=AmericanTypewriter size=16 color=purple>different colours</font> <font face=Futura size=32 color='#dd1100'>and sizes</font>" forKey:@"text"];
+ row4[@"text"] = @"<font face='HelveticaNeue-CondensedBold' size=20 color='#CCFF00'>Text with</font> <font face=AmericanTypewriter size=16 color=purple>different colours</font> <font face=Futura size=32 color='#dd1100'>and sizes</font>";
[self.dataArray addObject:row4];
NSMutableDictionary *row5 = [NSMutableDictionary dictionary];
- [row5 setObject:@"<font face='HelveticaNeue-CondensedBold' size=20 stroke=1>Text with strokes</font> " forKey:@"text"];
+ row5[@"text"] = @"<font face='HelveticaNeue-CondensedBold' size=20 stroke=1>Text with strokes</font> ";
[self.dataArray addObject:row5];
NSMutableDictionary *row6 = [NSMutableDictionary dictionary];
- [row6 setObject:@"<font face='HelveticaNeue-CondensedBold' size=20 kern=35>KERN</font> " forKey:@"text"];
+ row6[@"text"] = @"<font face='HelveticaNeue-CondensedBold' size=20 kern=35>KERN</font> ";
[self.dataArray addObject:row6];
NSMutableDictionary *row7 = [NSMutableDictionary dictionary];
- [row7 setObject:@"<font face='HelveticaNeue-CondensedBold' size=14><p align=justify><font color=red>JUSTIFY</font> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim </p> <p align=left><font color=red>LEFT ALIGNED</font> veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><br><p align=right><font color=red>RIGHT ALIGNED</font> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p><br><p align=center><font color=red>CENTER ALIGNED</font> Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p></font> " forKey:@"text"];
+ row7[@"text"] = @"<font face='HelveticaNeue-CondensedBold' size=14><p align=justify><font color=red>JUSTIFY</font> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim </p> <p align=left><font color=red>LEFT ALIGNED</font> veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p><br><p align=right><font color=red>RIGHT ALIGNED</font> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p><br><p align=center><font color=red>CENTER ALIGNED</font> Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p></font> ";
[self.dataArray addObject:row7];
NSMutableDictionary *row20 = [NSMutableDictionary dictionary];
- [row20 setObject:@"<p indent=20>Indented bla bla <bi>bla bla bla bla</bi> bla bla bla bla bla bla bla</p>" forKey:@"text"];
+ row20[@"text"] = @"<p indent=20>Indented bla bla <bi>bla bla bla bla</bi> bla bla bla bla bla bla bla</p>";
[self.dataArray addObject:row20];
}
return self;
@@ -106,19 +106,19 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
- NSMutableDictionary *rowInfo = [self.dataArray objectAtIndex:indexPath.row];
- if ([rowInfo objectForKey:@"cell_height"])
+ NSMutableDictionary *rowInfo = (self.dataArray)[indexPath.row];
+ if (rowInfo[@"cell_height"])
{
- return [[rowInfo objectForKey:@"cell_height"] floatValue];
+ return [rowInfo[@"cell_height"] floatValue];
}
else
{
RTLabel *rtLabel = [DemoTableViewCell textLabel];
rtLabel.lineSpacing = 20.0;
- [rtLabel setText:[rowInfo objectForKey:@"text"]];
+ [rtLabel setText:rowInfo[@"text"]];
CGSize optimumSize = [rtLabel optimumSize];
- [rowInfo setObject:[NSNumber numberWithFloat:optimumSize.height+20] forKey:@"cell_height"];
- return [[rowInfo objectForKey:@"cell_height"] floatValue];
+ rowInfo[@"cell_height"] = @(optimumSize.height+20);
+ return [rowInfo[@"cell_height"] floatValue];
}
}
@@ -141,7 +141,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [[DemoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell.rtLabel setDelegate:self];
}
- [cell.rtLabel setText:[[self.dataArray objectAtIndex:indexPath.row] objectForKey:@"text"]];
+ [cell.rtLabel setText:(self.dataArray)[indexPath.row][@"text"]];
cell.rtLabel.lineSpacing = 20.0;
return cell;
}
View
10 RTLabelProject/Classes/RTLabel.h
@@ -60,16 +60,16 @@ typedef enum
@end
@interface RTLabelComponent : NSObject
-@property (nonatomic, assign) int componentIndex;
+@property (nonatomic, assign) NSInteger componentIndex;
@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
@@ -92,7 +92,7 @@ typedef enum
@property (nonatomic, assign) CGSize optimumSize;
@property (nonatomic, assign) RTTextLineBreakMode lineBreakMode;
@property (nonatomic, assign) CGFloat lineSpacing;
-@property (nonatomic, assign) int currentSelectedButtonComponentIndex;
+@property (nonatomic, assign) NSInteger currentSelectedButtonComponentIndex;
@property (nonatomic, assign) CFRange visibleRange;
@property (nonatomic, assign) BOOL highlighted;
View
142 RTLabelProject/Classes/RTLabel.m
@@ -38,7 +38,7 @@
#import "RTLabel.h"
@interface RTLabelButton : UIButton
-@property (nonatomic, assign) int componentIndex;
+@property (nonatomic, assign) NSInteger componentIndex;
@property (nonatomic) NSURL *url;
@end
@@ -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) {
@@ -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];
}
@@ -83,7 +83,7 @@ - (NSString*)description
{
NSMutableString *desc = [NSMutableString string];
[desc appendFormat:@"text: %@", self.text];
- [desc appendFormat:@", position: %i", self.position];
+ [desc appendFormat:@", position: %@", @(self.position)];
if (self.tagLabel) [desc appendFormat:@", tag: %@", self.tagLabel];
if (self.attributes) [desc appendFormat:@", attributes: %@", self.attributes];
return desc;
@@ -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
@@ -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)
@@ -271,14 +271,16 @@ - (void)render
}
else
{
- [self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
+ //[self applyBoldStyleToText:attrString atPosition:component.position withLength:[component.text length]];
[self applySingleUnderlineText:attrString atPosition:component.position withLength:[component.text length]];
}
}
- NSString *value = [component.attributes objectForKey:@"href"];
+ NSString *value = (component.attributes)[@"href"];
value = [value stringByReplacingOccurrencesOfString:@"'" withString:@""];
- [component.attributes setObject:value forKey:@"href"];
+
+ if(value)
+ component.attributes[@"href"] = value;
[links addObject:component];
}
@@ -294,9 +296,9 @@ - (void)render
[self applyDoubleUnderlineText:attrString atPosition:component.position withLength:[component.text length]];
}
- if ([component.attributes objectForKey:@"color"])
+ if ((component.attributes)[@"color"])
{
- NSString *value = [component.attributes objectForKey:@"color"];
+ NSString *value = (component.attributes)[@"color"];
[self applyUnderlineColor:value toText:attrString atPosition:component.position withLength:[component.text length]];
}
}
@@ -338,7 +340,7 @@ - (void)render
for (RTLabelComponent *linkableComponents in links)
{
- float height = 0.0;
+ CGFloat height = 0.0;
CFArrayRef frameLines = CTFrameGetLines(frame);
for (CFIndex i=0; i<CFArrayGetCount(frameLines); i++)
{
@@ -365,7 +367,7 @@ - (void)render
[button setBackgroundColor:[UIColor colorWithWhite:0 alpha:0]];
[button setComponentIndex:linkableComponents.componentIndex];
- [button setUrl:[NSURL URLWithString:[linkableComponents.attributes objectForKey:@"href"]]];
+ [button setUrl:[NSURL URLWithString:(linkableComponents.attributes)[@"href"]]];
[button addTarget:self action:@selector(onButtonTouchDown:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(onButtonTouchUpOutside:) forControlEvents:UIControlEventTouchUpOutside];
[button addTarget:self action:@selector(onButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
@@ -393,7 +395,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) ) );
@@ -414,8 +416,8 @@ - (void)applyParagraphStyleToText:(CFMutableAttributedStringRef)text attributes:
for (NSUInteger i=0; i<[[attributes allKeys] count]; i++)
{
- NSString *key = [[attributes allKeys] objectAtIndex:i];
- id value = [attributes objectForKey:key];
+ NSString *key = [attributes allKeys][i];
+ id value = attributes[key];
if ([key caseInsensitiveCompare:@"align"] == NSOrderedSame)
{
if ([value caseInsensitiveCompare:@"left"] == NSOrderedSame)
@@ -494,7 +496,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) ) );
@@ -509,9 +511,9 @@ - (void)applyCenterStyleToText:(CFMutableAttributedStringRef)text attributes:(NS
CGFloat minLineHeight = 0;
CGFloat paragraphSpacing = 0.0;
CGFloat paragraphSpacingBefore = 0.0;
- int textAlignment = _textAlignment;
- int lineBreakMode = _lineBreakMode;
- int lineSpacing = (int)_lineSpacing;
+ NSInteger textAlignment = _textAlignment;
+ NSInteger lineBreakMode = _lineBreakMode;
+ NSInteger lineSpacing = (NSInteger)_lineSpacing;
textAlignment = kCTCenterTextAlignment;
@@ -539,17 +541,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]);
+ CFAttributedStringSetAttribute(text, CFRangeMake(position, length), kCTUnderlineStyleAttributeName, (__bridge CFNumberRef)@(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]);
+ CFAttributedStringSetAttribute(text, CFRangeMake(position, length), kCTUnderlineStyleAttributeName, (__bridge CFNumberRef)@(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);
@@ -562,11 +564,11 @@ - (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)
{
- NSString *value = [attributes objectForKey:key];
+ NSString *value = attributes[key];
value = [value stringByReplacingOccurrencesOfString:@"'" withString:@""];
if ([key caseInsensitiveCompare:@"color"] == NSOrderedSame)
@@ -575,15 +577,15 @@ - (void)applyFontAttributes:(NSDictionary*)attributes toText:(CFMutableAttribute
}
else if ([key caseInsensitiveCompare:@"stroke"] == NSOrderedSame)
{
- CFAttributedStringSetAttribute(text, CFRangeMake(position, length), kCTStrokeWidthAttributeName, (__bridge CFTypeRef)([NSNumber numberWithFloat:[[attributes objectForKey:@"stroke"] intValue]]));
+ CFAttributedStringSetAttribute(text, CFRangeMake(position, length), kCTStrokeWidthAttributeName, (__bridge CFTypeRef)([NSNumber numberWithFloat:[attributes[@"stroke"] intValue]]));
}
else if ([key caseInsensitiveCompare:@"kern"] == NSOrderedSame)
{
- CFAttributedStringSetAttribute(text, CFRangeMake(position, length), kCTKernAttributeName, (__bridge CFTypeRef)([NSNumber numberWithFloat:[[attributes objectForKey:@"kern"] intValue]]));
+ CFAttributedStringSetAttribute(text, CFRangeMake(position, length), kCTKernAttributeName, (__bridge CFTypeRef)([NSNumber numberWithFloat:[attributes[@"kern"] intValue]]));
}
else if ([key caseInsensitiveCompare:@"underline"] == NSOrderedSame)
{
- int numberOfLines = [value intValue];
+ NSInteger numberOfLines = [value intValue];
if (numberOfLines==1)
{
[self applySingleUnderlineText:text atPosition:position withLength:length];
@@ -607,21 +609,21 @@ - (void)applyFontAttributes:(NSDictionary*)attributes toText:(CFMutableAttribute
}
UIFont *font = nil;
- if ([attributes objectForKey:@"face"] && [attributes objectForKey:@"size"])
+ if (attributes[@"face"] && attributes[@"size"])
{
- NSString *fontName = [attributes objectForKey:@"face"];
+ NSString *fontName = attributes[@"face"];
fontName = [fontName stringByReplacingOccurrencesOfString:@"'" withString:@""];
- font = [UIFont fontWithName:fontName size:[[attributes objectForKey:@"size"] intValue]];
+ font = [UIFont fontWithName:fontName size:[attributes[@"size"] intValue]];
}
- else if ([attributes objectForKey:@"face"] && ![attributes objectForKey:@"size"])
+ else if (attributes[@"face"] && !attributes[@"size"])
{
- NSString *fontName = [attributes objectForKey:@"face"];
+ NSString *fontName = attributes[@"face"];
fontName = [fontName stringByReplacingOccurrencesOfString:@"'" withString:@""];
font = [UIFont fontWithName:fontName size:self.font.pointSize];
}
- else if (![attributes objectForKey:@"face"] && [attributes objectForKey:@"size"])
+ else if (!attributes[@"face"] && attributes[@"size"])
{
- font = [UIFont fontWithName:[self.font fontName] size:[[attributes objectForKey:@"size"] intValue]];
+ font = [UIFont fontWithName:[self.font fontName] size:[attributes[@"size"] intValue]];
}
if (font)
{
@@ -631,7 +633,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);
@@ -644,7 +646,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);
@@ -661,7 +663,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)
@@ -669,7 +671,7 @@ - (void)applyColor:(NSString*)value toText:(CFMutableAttributedStringRef)text at
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
value = [value stringByReplacingOccurrencesOfString:@"#" withString:@""];
NSArray *colorComponents = [self colorForHex:value];
- CGFloat components[] = { [[colorComponents objectAtIndex:0] floatValue] , [[colorComponents objectAtIndex:1] floatValue] , [[colorComponents objectAtIndex:2] floatValue] , [[colorComponents objectAtIndex:3] floatValue] };
+ CGFloat components[] = { [colorComponents[0] floatValue] , [colorComponents[1] floatValue] , [colorComponents[2] floatValue] , [colorComponents[3] floatValue] };
CGColorRef color = CGColorCreate(rgbColorSpace, components);
CFAttributedStringSetAttribute(text, CFRangeMake(position, length),kCTForegroundColorAttributeName, color);
CFRelease(color);
@@ -686,7 +688,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:@""];
@@ -694,7 +696,7 @@ - (void)applyUnderlineColor:(NSString*)value toText:(CFMutableAttributedStringRe
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
value = [value stringByReplacingOccurrencesOfString:@"#" withString:@"0x"];
NSArray *colorComponents = [self colorForHex:value];
- CGFloat components[] = { [[colorComponents objectAtIndex:0] floatValue] , [[colorComponents objectAtIndex:1] floatValue] , [[colorComponents objectAtIndex:2] floatValue] , [[colorComponents objectAtIndex:3] floatValue] };
+ CGFloat components[] = { [colorComponents[0] floatValue] , [colorComponents[1] floatValue] , [colorComponents[2] floatValue] , [colorComponents[3] floatValue] };
CGColorRef color = CGColorCreate(rgbColorSpace, components);
CFAttributedStringSetAttribute(text, CFRangeMake(position, length),kCTUnderlineColorAttributeName, color);
CGColorRelease(color);
@@ -803,9 +805,9 @@ - (CGFloat)frameHeight:(CTFrameRef)theFrame
for (CFIndex index = 0; index < CFArrayGetCount(lines); index++) {
CTLineRef line = (CTLineRef)CFArrayGetValueAtIndex(lines, index);
CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
- height += (ascent + fabsf(descent) + leading);
+ height += (ascent + fabs(descent) + leading);
}
- return ceilf(height);
+ return (CGFloat)ceil(height);
}
- (void)dealloc
@@ -865,7 +867,7 @@ + (RTLabelExtractedComponent*)extractTextStyleFromText:(NSString*)data paragraph
NSMutableArray *components = [NSMutableArray array];
- int last_position = 0;
+ NSInteger last_position = 0;
scanner = [NSScanner scannerWithString:data];
while (![scanner isAtEnd])
{
@@ -873,7 +875,7 @@ + (RTLabelExtractedComponent*)extractTextStyleFromText:(NSString*)data paragraph
[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)
@@ -895,9 +897,9 @@ + (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];
+ RTLabelComponent *component = components[i];
if (component.text==nil && [component.tagLabel isEqualToString:tag])
{
NSString *text2 = [data substringWithRange:NSMakeRange(component.position, position-component.position)];
@@ -911,14 +913,14 @@ + (RTLabelExtractedComponent*)extractTextStyleFromText:(NSString*)data paragraph
{
// start of tag
NSArray *textComponents = [[text substringFromIndex:1] componentsSeparatedByString:@" "];
- tag = [textComponents objectAtIndex:0];
+ tag = textComponents[0];
//NSLog(@"start of tag: %@", tag);
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
for (NSUInteger i=1; i<[textComponents count]; i++)
{
- NSArray *pair = [[textComponents objectAtIndex:i] componentsSeparatedByString:@"="];
+ NSArray *pair = [textComponents[i] componentsSeparatedByString:@"="];
if ([pair count] > 0) {
- NSString *key = [[pair objectAtIndex:0] lowercaseString];
+ NSString *key = [pair[0] lowercaseString];
if ([pair count]>=2) {
// Trim " charactere
@@ -926,9 +928,9 @@ + (RTLabelExtractedComponent*)extractTextStyleFromText:(NSString*)data paragraph
value = [value stringByReplacingOccurrencesOfString:@"\"" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, 1)];
value = [value stringByReplacingOccurrencesOfString:@"\"" withString:@"" options:NSLiteralSearch range:NSMakeRange([value length]-1, 1)];
- [attributes setObject:value forKey:key];
+ attributes[key] = value;
} else if ([pair count]==1) {
- [attributes setObject:key forKey:key];
+ attributes[key] = key;
}
}
}
@@ -956,7 +958,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
@@ -979,10 +981,10 @@ - (void)parse:(NSString *)data valid_tags:(NSArray *)valid_tags
NSArray *rawAttributes = [tag componentsSeparatedByString:@" "];
for (NSUInteger i=1; i<[rawAttributes count]; i++)
{
- NSArray *pair = [[rawAttributes objectAtIndex:i] componentsSeparatedByString:@"="];
+ NSArray *pair = [rawAttributes[i] componentsSeparatedByString:@"="];
if ([pair count]==2)
{
- [attributes setObject:[pair objectAtIndex:1] forKey:[pair objectAtIndex:0]];
+ attributes[pair[0]] = pair[1];
}
}
@@ -995,7 +997,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)
{
@@ -1051,7 +1053,7 @@ - (NSArray*)colorForHex:(NSString *)hexColor
[[NSScanner scannerWithString:gString] scanHexInt:&g];
[[NSScanner scannerWithString:bString] scanHexInt:&b];
- NSArray *components = [NSArray arrayWithObjects:[NSNumber numberWithFloat:((float) r / 255.0f)],[NSNumber numberWithFloat:((float) g / 255.0f)],[NSNumber numberWithFloat:((float) b / 255.0f)],[NSNumber numberWithFloat:1.0],nil];
+ NSArray *components = @[@((float) r / 255.0f),@((float) g / 255.0f),@((float) b / 255.0f),@1.0f];
return components;
}
@@ -1068,8 +1070,8 @@ - (NSString*)visibleText
- (void)setText:(NSString *)text extractedTextStyle:(NSDictionary*)extractTextStyle
{
_text = [text stringByReplacingOccurrencesOfString:@"<br>" withString:@"\n"];
- [self setTextComponents:[extractTextStyle objectForKey:@"textComponents"]];
- [self setPlainText:[extractTextStyle objectForKey:@"plainText"]];
+ [self setTextComponents:extractTextStyle[@"textComponents"]];
+ [self setPlainText:extractTextStyle[@"plainText"]];
[self setNeedsDisplay];
}
@@ -1078,7 +1080,7 @@ + (NSDictionary*)preExtractTextStyle:(NSString*)data
NSString* paragraphReplacement = @"\n";
RTLabelExtractedComponent *component = [RTLabel extractTextStyleFromText:data paragraphReplacement:paragraphReplacement];
- return [NSDictionary dictionaryWithObjectsAndKeys:component.textComponents, @"textComponents", component.plainText, @"plainText", nil];
+ return @{@"textComponents": component.textComponents, @"plainText": component.plainText};
}
View
2  RTLabelProject/RTLabelProject.xcodeproj/project.pbxproj
@@ -200,6 +200,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_OBJCPP_ARC_ABI = YES;
COPY_PHASE_STRIP = NO;
@@ -218,6 +219,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_OBJCPP_ARC_ABI = YES;
COPY_PHASE_STRIP = YES;
View
41 RTLabelProject/RTLabelProject.xcodeproj/project.xcworkspace/xcshareddata/RTLabelProject.xccheckout
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IDESourceControlProjectFavoriteDictionaryKey</key>
+ <false/>
+ <key>IDESourceControlProjectIdentifier</key>
+ <string>68987889-3702-4203-AE36-0E6FDF45FDE5</string>
+ <key>IDESourceControlProjectName</key>
+ <string>RTLabelProject</string>
+ <key>IDESourceControlProjectOriginsDictionary</key>
+ <dict>
+ <key>F1F3DEE1-0165-4AE2-9FBC-0C57006DCF73</key>
+ <string>ssh://github.com/devinross/RTLabel.git</string>
+ </dict>
+ <key>IDESourceControlProjectPath</key>
+ <string>RTLabelProject/RTLabelProject.xcodeproj/project.xcworkspace</string>
+ <key>IDESourceControlProjectRelativeInstallPathDictionary</key>
+ <dict>
+ <key>F1F3DEE1-0165-4AE2-9FBC-0C57006DCF73</key>
+ <string>../../..</string>
+ </dict>
+ <key>IDESourceControlProjectURL</key>
+ <string>ssh://github.com/devinross/RTLabel.git</string>
+ <key>IDESourceControlProjectVersion</key>
+ <integer>110</integer>
+ <key>IDESourceControlProjectWCCIdentifier</key>
+ <string>F1F3DEE1-0165-4AE2-9FBC-0C57006DCF73</string>
+ <key>IDESourceControlProjectWCConfigurations</key>
+ <array>
+ <dict>
+ <key>IDESourceControlRepositoryExtensionIdentifierKey</key>
+ <string>public.vcs.git</string>
+ <key>IDESourceControlWCCIdentifierKey</key>
+ <string>F1F3DEE1-0165-4AE2-9FBC-0C57006DCF73</string>
+ <key>IDESourceControlWCCName</key>
+ <string>RTLabel</string>
+ </dict>
+ </array>
+</dict>
+</plist>
Something went wrong with that request. Please try again.