From dc36dbd1e5e40809f65ef384d0e41a454893dba7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Lilleb=C3=B8=20Holm?=
Date: Tue, 8 Jul 2014 10:47:05 +0200
Subject: [PATCH 01/10] - Fixed so the text edit menu when clicking and holding
has the same features set as the toolbar is setup with
---
RichTextEditor/Source/RichTextEditor.m | 37 ++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/RichTextEditor/Source/RichTextEditor.m b/RichTextEditor/Source/RichTextEditor.m
index 86231e9..c5bb4a5 100644
--- a/RichTextEditor/Source/RichTextEditor.m
+++ b/RichTextEditor/Source/RichTextEditor.m
@@ -94,6 +94,11 @@ - (void)commonInitialization
[self updateToolbarState];
}
+-(void)setDataSource:(id)dataSource{
+ _dataSource = dataSource;
+ [self setupMenuItems];
+}
+
#pragma mark - Override Methods -
- (void)setSelectedTextRange:(UITextRange *)selectedTextRange
@@ -157,8 +162,36 @@ - (void)setupMenuItems
UIMenuItem *italicItem = [[UIMenuItem alloc] initWithTitle:@"Italic" action:@selector(richTextEditorToolbarDidSelectItalic)];
UIMenuItem *underlineItem = [[UIMenuItem alloc] initWithTitle:@"Underline" action:@selector(richTextEditorToolbarDidSelectUnderline)];
UIMenuItem *strikeThroughItem = [[UIMenuItem alloc] initWithTitle:@"Strike" action:@selector(richTextEditorToolbarDidSelectStrikeThrough)];
-
- [[UIMenuController sharedMenuController] setMenuItems:@[selectParagraph, boldItem, italicItem, underlineItem, strikeThroughItem]];
+
+ RichTextEditorFeature features = [self featuresEnabledForRichTextEditorToolbar];
+ if(features == RichTextEditorFeatureAll){
+ [[UIMenuController sharedMenuController] setMenuItems:@[selectParagraph, boldItem, italicItem, underlineItem, strikeThroughItem]];
+ }else{
+ NSMutableArray *array = [NSMutableArray array];
+
+ if(features & RichTextEditorFeatureParagraphIndentation){
+ [array addObject:selectParagraph];
+ }
+
+ if(features & RichTextEditorFeatureBold){
+ [array addObject:boldItem];
+ }
+
+ if(features & RichTextEditorFeatureItalic){
+ [array addObject:italicItem];
+ }
+
+ if(features & RichTextEditorFeatureUnderline){
+ [array addObject:underlineItem];
+ }
+
+ if(features & RichTextEditorFeatureStrikeThrough){
+ [array addObject:strikeThroughItem];
+ }
+
+ [[UIMenuController sharedMenuController] setMenuItems:array];
+ }
+
}
- (void)selectParagraph:(id)sender
From f71d43ace3d9cd8b5496013291d3f99d48ed89d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Lilleb=C3=B8=20Holm?=
Date: Tue, 8 Jul 2014 10:48:00 +0200
Subject: [PATCH 02/10] - Fixed so the menu bar state is updated when new text
is applied. It often had the wrong ui state when starting with new text
---
RichTextEditor/Source/RichTextEditor.m | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/RichTextEditor/Source/RichTextEditor.m b/RichTextEditor/Source/RichTextEditor.m
index c5bb4a5..5e54b09 100644
--- a/RichTextEditor/Source/RichTextEditor.m
+++ b/RichTextEditor/Source/RichTextEditor.m
@@ -391,6 +391,11 @@ - (void)enumarateThroughParagraphsInRange:(NSRange)range withBlock:(void (^)(NSR
[self setSelectedRange:fullRange];
}
+-(void)setAttributedText:(NSAttributedString *)attributedText{
+ [super setAttributedText:attributedText];
+ [self updateToolbarState];
+}
+
- (void)updateToolbarState
{
// If no text exists or typing attributes is in progress update toolbar using typing attributes instead of selected text
From 749f55741666d9bec65ab720890f0cdfbbe20912 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Lilleb=C3=B8=20Holm?=
Date: Tue, 8 Jul 2014 10:49:22 +0200
Subject: [PATCH 03/10] - Fixed so the button state actually works both in text
selection mode and in single cursor position mode. It had very often the
wrong state on toolbar when setting the cursor before bold/italic text and
then starting typing (ui indicated bold, but text with no format was
presented
---
RichTextEditor/Source/RichTextEditor.m | 33 +++++++++++++++++++-------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/RichTextEditor/Source/RichTextEditor.m b/RichTextEditor/Source/RichTextEditor.m
index 5e54b09..4608807 100644
--- a/RichTextEditor/Source/RichTextEditor.m
+++ b/RichTextEditor/Source/RichTextEditor.m
@@ -405,10 +405,16 @@ - (void)updateToolbarState
}
else
{
- int location = [self offsetFromPosition:self.beginningOfDocument toPosition:self.selectedTextRange.start];
-
- if (location == self.text.length)
- location --;
+ NSInteger location = [self offsetFromPosition:self.beginningOfDocument toPosition:self.selectedTextRange.start];
+ if(self.selectedRange.length > 0){
+ if (location == self.text.length)
+ location --;
+ }else{
+ if (location != 0)
+ location --;
+ }
+
+
[self.toolBar updateStateWithAttributes:[self.attributedText attributesAtIndex:location effectiveRange:nil]];
}
@@ -427,9 +433,13 @@ - (NSRange)fullRangeFromArrayOfParagraphRanges:(NSArray *)paragraphRanges
- (UIFont *)fontAtIndex:(NSInteger)index
{
// If index at end of string, get attributes starting from previous character
- if (index == self.attributedText.string.length && [self hasText])
- --index;
-
+ if(self.selectedRange.length > 0){
+ if (index == self.attributedText.string.length && [self hasText])
+ index --;
+ }else{
+ if (index != 0)
+ index --;
+ }
// If no text exists get font from typing attributes
NSDictionary *dictionary = ([self hasText])
? [self.attributedText attributesAtIndex:index effectiveRange:nil]
@@ -441,8 +451,13 @@ - (UIFont *)fontAtIndex:(NSInteger)index
- (NSDictionary *)dictionaryAtIndex:(NSInteger)index
{
// If index at end of string, get attributes starting from previous character
- if (index == self.attributedText.string.length && [self hasText])
- --index;
+ if(self.selectedRange.length > 0){
+ if (index == self.attributedText.string.length && [self hasText])
+ index --;
+ }else{
+ if (index != 0)
+ index --;
+ }
// If no text exists get font from typing attributes
return ([self hasText])
From 5adb8aab3f1eaa39fb43f4b141c4d950255067c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Lilleb=C3=B8=20Holm?=
Date: Tue, 8 Jul 2014 10:50:49 +0200
Subject: [PATCH 04/10] - Moved enums to use inbuilt NS_ENUM macro
---
.../RichTextEditorColorPickerViewController.h | 8 +++----
RichTextEditor/Source/RichTextEditorToolbar.h | 22 +++++++++----------
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/RichTextEditor/Source/RichTextEditorColorPickerViewController.h b/RichTextEditor/Source/RichTextEditorColorPickerViewController.h
index 0bdaeb5..6f23eca 100644
--- a/RichTextEditor/Source/RichTextEditorColorPickerViewController.h
+++ b/RichTextEditor/Source/RichTextEditorColorPickerViewController.h
@@ -29,10 +29,10 @@
#import
#import "UIView+RichTextEditor.h"
-typedef enum {
- RichTextEditorColorPickerActionTextForegroudColor,
- RichTextEditorColorPickerActionTextBackgroundColor
-}RichTextEditorColorPickerAction;
+typedef NS_ENUM(NSUInteger, RichTextEditorColorPickerAction) {
+ RichTextEditorColorPickerActionTextForegroudColor,
+ RichTextEditorColorPickerActionTextBackgroundColor
+};
@protocol RichTextEditorColorPickerViewControllerDelegate
- (void)richTextEditorColorPickerViewControllerDidSelectColor:(UIColor *)color withAction:(RichTextEditorColorPickerAction)action;
diff --git a/RichTextEditor/Source/RichTextEditorToolbar.h b/RichTextEditor/Source/RichTextEditorToolbar.h
index ff6be4d..7b84f13 100644
--- a/RichTextEditor/Source/RichTextEditorToolbar.h
+++ b/RichTextEditor/Source/RichTextEditorToolbar.h
@@ -27,18 +27,18 @@
#import
-typedef enum{
- RichTextEditorToolbarPresentationStyleModal,
- RichTextEditorToolbarPresentationStylePopover
-}RichTextEditorToolbarPresentationStyle;
+typedef NS_ENUM(NSUInteger, RichTextEditorToolbarPresentationStyle) {
+ RichTextEditorToolbarPresentationStyleModal,
+ RichTextEditorToolbarPresentationStylePopover
+};
-typedef enum{
- ParagraphIndentationIncrease,
- ParagraphIndentationDecrease
-}ParagraphIndentation;
+typedef NS_ENUM(NSUInteger, ParagraphIndentation) {
+ ParagraphIndentationIncrease,
+ ParagraphIndentationDecrease
+};
-typedef enum{
- RichTextEditorFeatureNone = 0,
+typedef NS_ENUM(NSUInteger, RichTextEditorFeature) {
+ RichTextEditorFeatureNone = 0,
RichTextEditorFeatureFont = 1 << 0,
RichTextEditorFeatureFontSize = 1 << 1,
RichTextEditorFeatureBold = 1 << 2,
@@ -54,7 +54,7 @@ typedef enum{
RichTextEditorFeatureParagraphIndentation = 1 << 12,
RichTextEditorFeatureParagraphFirstLineIndentation = 1 << 13,
RichTextEditorFeatureAll = 1 << 14
-}RichTextEditorFeature;
+};
@protocol RichTextEditorToolbarDelegate
- (void)richTextEditorToolbarDidSelectBold;
From 5833b6c604d7185727d00a86b7b34466de82cd0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Lilleb=C3=B8=20Holm?=
Date: Tue, 8 Jul 2014 10:52:48 +0200
Subject: [PATCH 05/10] - Fixed warnings when using int instead of NSInteger
---
.../Source/Categories/NSAttributedString+RichTextEditor.m | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m b/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m
index 15052e2..c951b22 100644
--- a/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m
+++ b/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m
@@ -41,7 +41,7 @@ - (NSRange)firstParagraphRangeFromTextRange:(NSRange)range
range.location-1 :
range.location;
- for (int i=startingRange ; i>=0 ; i--)
+ for (NSInteger i=startingRange ; i>=0 ; i--)
{
char c = [self.string characterAtIndex:i];
if (c == '\n')
@@ -55,7 +55,7 @@ - (NSRange)firstParagraphRangeFromTextRange:(NSRange)range
NSInteger moveForwardIndex = (range.location > start) ? range.location : start;
- for (int i=moveForwardIndex; i<= self.string.length-1 ; i++)
+ for (NSInteger i=moveForwardIndex; i<= self.string.length-1 ; i++)
{
char c = [self.string characterAtIndex:i];
if (c == '\n')
From c895a75d84854f1c2473d101ad98db19c03373f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Lilleb=C3=B8=20Holm?=
Date: Tue, 8 Jul 2014 10:54:25 +0200
Subject: [PATCH 06/10] - Added .gitignore to not include userdata in project
and added auto created workspace
---
.gitignore | 5 +++++
.../project.xcworkspace/contents.xcworkspacedata | 7 +++++++
2 files changed, 12 insertions(+)
create mode 100644 .gitignore
create mode 100644 RichTextEditor.xcodeproj/project.xcworkspace/contents.xcworkspacedata
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..915d0ef
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+/RichTextEditor.xcodeproj/xcuserdata/
+
+UserInterfaceState.xcuserstate
+
+RichTextEditor.xccheckout
diff --git a/RichTextEditor.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/RichTextEditor.xcodeproj/project.xcworkspace/contents.xcworkspacedata
new file mode 100644
index 0000000..242f037
--- /dev/null
+++ b/RichTextEditor.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+
+
+
+
+
From d3c0c2e0253617bbdfc5692d507e951a176c8a4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Lilleb=C3=B8=20Holm?=
Date: Tue, 8 Jul 2014 10:55:10 +0200
Subject: [PATCH 07/10] - Added url insertion support
---
RichTextEditor.xcodeproj/project.pbxproj | 6 ++
RichTextEditor/Source/Assets/link.png | Bin 1266 -> 4091 bytes
RichTextEditor/Source/Assets/link@2x.png | Bin 0 -> 5447 bytes
.../NSAttributedString+RichTextEditor.m | 12 ++-
RichTextEditor/Source/RichTextEditor.m | 32 +++++++
.../RichTextEditorInsertLinkViewController.h | 27 ++++++
.../RichTextEditorInsertLinkViewController.m | 86 ++++++++++++++++++
RichTextEditor/Source/RichTextEditorToolbar.h | 4 +-
RichTextEditor/Source/RichTextEditorToolbar.m | 31 ++++++-
9 files changed, 194 insertions(+), 4 deletions(-)
create mode 100644 RichTextEditor/Source/Assets/link@2x.png
create mode 100644 RichTextEditor/Source/RichTextEditorInsertLinkViewController.h
create mode 100644 RichTextEditor/Source/RichTextEditorInsertLinkViewController.m
diff --git a/RichTextEditor.xcodeproj/project.pbxproj b/RichTextEditor.xcodeproj/project.pbxproj
index 236b1e9..35e16df 100644
--- a/RichTextEditor.xcodeproj/project.pbxproj
+++ b/RichTextEditor.xcodeproj/project.pbxproj
@@ -101,6 +101,7 @@
1AFAED8617C804AB00E450B0 /* numlist@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AFAED8417C804AB00E450B0 /* numlist@2x.png */; };
1AFAED8717C804AB00E450B0 /* bullist@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AFAED8517C804AB00E450B0 /* bullist@2x.png */; };
1AFAED8917C80FC600E450B0 /* dropDownTriangle@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AFAED8817C80FC600E450B0 /* dropDownTriangle@2x.png */; };
+ E1A1B1E1196ABAE900513A15 /* RichTextEditorInsertLinkViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E1A1B1E0196ABAE900513A15 /* RichTextEditorInsertLinkViewController.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -229,6 +230,8 @@
1AFAED8417C804AB00E450B0 /* numlist@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "numlist@2x.png"; sourceTree = ""; };
1AFAED8517C804AB00E450B0 /* bullist@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "bullist@2x.png"; sourceTree = ""; };
1AFAED8817C80FC600E450B0 /* dropDownTriangle@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dropDownTriangle@2x.png"; sourceTree = ""; };
+ E1A1B1DF196ABAE800513A15 /* RichTextEditorInsertLinkViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RichTextEditorInsertLinkViewController.h; sourceTree = ""; };
+ E1A1B1E0196ABAE900513A15 /* RichTextEditorInsertLinkViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RichTextEditorInsertLinkViewController.m; sourceTree = ""; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -275,6 +278,8 @@
153F9581179F9953005B2487 /* RichTextEditorFontSizePickerViewController.h */,
153F9582179F9953005B2487 /* RichTextEditorFontSizePickerViewController.m */,
153F9583179F9953005B2487 /* RichTextEditorPopover.h */,
+ E1A1B1DF196ABAE800513A15 /* RichTextEditorInsertLinkViewController.h */,
+ E1A1B1E0196ABAE900513A15 /* RichTextEditorInsertLinkViewController.m */,
);
path = Source;
sourceTree = "";
@@ -658,6 +663,7 @@
153F95A0179F9953005B2487 /* RichTextEditor.m in Sources */,
153F958C179F9953005B2487 /* UIView+RichTextEditor.m in Sources */,
153F959F179F9953005B2487 /* WETouchableView.m in Sources */,
+ E1A1B1E1196ABAE900513A15 /* RichTextEditorInsertLinkViewController.m in Sources */,
158389231735A5D7006DE713 /* AppDelegate.m in Sources */,
158389321735A5D7006DE713 /* ViewController.m in Sources */,
153F95A1179F9953005B2487 /* RichTextEditorColorPickerViewController.m in Sources */,
diff --git a/RichTextEditor/Source/Assets/link.png b/RichTextEditor/Source/Assets/link.png
index b261c636ea706ab1bddbc3e9d2a495299c95d43f..d23bd07f10c04a8943d5c5aca34c33db4db73fc5 100644
GIT binary patch
literal 4091
zcmZuz2UJtrwoM>PZ%PLdBLo#l=+awgQIL)aH3@{?1SAxxQlyF0Py`IUNYS8DB=jao
zLma8pq&VU7lw|Il-
z1m7y@ae$2D5aC8tF;NhIty4PeY?mz@%-Vpuv0!^`c80r=*m1h=tVTWU##-77Q;BYL
z8`ZKurgIK^Q8N=uFUBXFHbTam07kzeK^=ZbV7Lqs$^Lb<-TKVgfvz1YZdM>O64*BD
z=m^r?)uMX$t3@R{yIik_wEYzt?$A6b)@lUt9Xkq30bhj+od(crkIE^BLbw*F(oIR-
zJW@xXS6dmErD7zdIEi$HkHK?YweH(xi=xf_Sp>*Dkry?@^HL^1vDs)kM|id<5k$1k
z68_{=bcY7lVur{8EbLqw8QFcP50GHbwi{f65Z&XXwAp#S#(k#((581Oy!2sC*i&%M
z2LzNl&Bue{5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>#~K8P#1Uz|foH~`Y7$$0r^c6{S*jI~K%%wg{5ZQuYZLC&%29xu
z0feH@05$N!IG*#C)(82>m!cxJ+!^n1
zOX*s7pRD)NC9|e&hvVwHd$c3;=8V`sO;ex@42Ih#FOb6Ldudu+EUAVRY#lShLD(8k
z9?!gD>#jGFeSw4-Vz6bMXO7n2T?Sm0;1;rpO6=}_0fWK)0kvBSfTWZxmi549OLL(h
z+h(mw=IdqFkoOqStG?PSZ1p#s7r>ww5EbUdI2sf4wulo$`QGUOgR2BhshpA7n3jAG
z?223BwX6%fqop{vcsxxXlvr2`L)tItXzmUJzN4PXcQU|s3cr*i^_A?Z6GM#+dEnT~
z!%JfGVb-Mf+Kdnw-#h|xJ}Nl!tU{L60e2aI3c$n~2=F{z%0280o#A5ro^;+6q)Lts
zM{XUkpRklBzB;OLQy7!4Qksj)FW@x}VyMIR2ha
NRh6_9E99+1{sD>r2jBnz
literal 0
HcmV?d00001
diff --git a/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m b/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m
index c951b22..b632340 100644
--- a/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m
+++ b/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m
@@ -131,7 +131,10 @@ - (NSString *)htmlString
BOOL hasUnderline = (!underline || underline.intValue == NSUnderlineStyleNone) ? NO :YES;
NSNumber *strikeThrough = [dictionary objectForKey:NSStrikethroughStyleAttributeName];
BOOL hasStrikeThrough = (!strikeThrough || strikeThrough.intValue == NSUnderlineStyleNone) ? NO :YES;
-
+ NSURL *url = [dictionary objectForKey:NSLinkAttributeName];
+
+
+
[fontString appendFormat:@""];
[fontString appendString:[[self.string substringFromIndex:range.location] substringToIndex:range.length]];
[fontString appendString:@""];
-
+
+ if(url){
+ [fontString insertString:[NSString stringWithFormat:@"",[url absoluteString]] atIndex:0];
+ [fontString insertString:@"" atIndex:fontString.length];
+ }
+
if ([font isBold])
{
[fontString insertString:@"" atIndex:0];
diff --git a/RichTextEditor/Source/RichTextEditor.m b/RichTextEditor/Source/RichTextEditor.m
index 4608807..e742cf0 100644
--- a/RichTextEditor/Source/RichTextEditor.m
+++ b/RichTextEditor/Source/RichTextEditor.m
@@ -355,6 +355,38 @@ - (void)richTextEditorToolbarDidSelectBulletPoint
// TODO: implement this
}
+- (void)richTextEditorToolbarDidInsertLink:(NSURL*) link displayText:(NSString*)displayText{
+
+ NSMutableAttributedString *attributedString = [self.attributedText mutableCopy];
+
+ NSMutableDictionary *attributes = [[self dictionaryAtIndex:self.selectedRange.location] mutableCopy];
+ UIFont *font = [attributes objectForKey:NSFontAttributeName];
+ font = [UIFont fontWithName:[font familyName] size:[font pointSize] boldTrait:NO italicTrait:NO];
+ [attributes setObject:font forKey:NSFontAttributeName];
+
+ NSMutableDictionary *cop = [attributes mutableCopy];
+ [cop setObject:link forKey:NSLinkAttributeName];
+ NSAttributedString *string = [[NSAttributedString alloc] initWithString:displayText attributes:cop];
+
+ NSRange oldRange = self.selectedRange;
+ oldRange.length = 0;
+ oldRange.location += displayText.length;
+
+ [attributedString insertAttributedString:string atIndex:self.selectedRange.location];
+
+ NSAttributedString *space = [[NSAttributedString alloc] initWithString:@" " attributes:attributes];
+ [attributedString insertAttributedString:space atIndex:oldRange.location];
+ oldRange.location += 1;
+
+ [self setAttributedText:attributedString];
+
+ [self updateToolbarState];
+ [self resignFirstResponder];
+ [self scrollRangeToVisible:oldRange];
+ [self becomeFirstResponder];
+ [self setSelectedRange:oldRange];
+}
+
#pragma mark - Private Methods -
- (CGRect)frameOfTextAtRange:(NSRange)range
diff --git a/RichTextEditor/Source/RichTextEditorInsertLinkViewController.h b/RichTextEditor/Source/RichTextEditorInsertLinkViewController.h
new file mode 100644
index 0000000..e4cf641
--- /dev/null
+++ b/RichTextEditor/Source/RichTextEditorInsertLinkViewController.h
@@ -0,0 +1,27 @@
+//
+// RichTextEditorInsertLinkViewController.h
+// RichTextEditor
+//
+// Created by Andreas Lillebø Holm on 07/07/14.
+// Copyright (c) 2014 Aryan Ghassemi. All rights reserved.
+//
+
+#import
+
+@protocol RichTextEditorInsertLinkViewControllerDelegate
+
+- (void)richTextEditorInsertLinkViewControllerInsertURL:(NSURL *)url withDisplayText:(NSString *)displayText;
+- (void)richTextEditorInsertLinkViewControllerDidCancel;
+
+@end
+
+@interface RichTextEditorInsertLinkViewController : UIViewController
+
+@property(nonatomic, weak) id delegate;
+
+- (void)doneSelected:(id)sender;
+- (void)closeSelected:(id)sender;
+
+@end
+
+
diff --git a/RichTextEditor/Source/RichTextEditorInsertLinkViewController.m b/RichTextEditor/Source/RichTextEditorInsertLinkViewController.m
new file mode 100644
index 0000000..2e8d110
--- /dev/null
+++ b/RichTextEditor/Source/RichTextEditorInsertLinkViewController.m
@@ -0,0 +1,86 @@
+//
+// RichTextEditorInsertLinkViewController.m
+// RichTextEditor
+//
+// Created by Andreas Lillebø Holm on 07/07/14.
+// Copyright (c) 2014 Aryan Ghassemi. All rights reserved.
+//
+
+#import "RichTextEditorInsertLinkViewController.h"
+
+@implementation RichTextEditorInsertLinkViewController{
+ UITextField *_urlField;
+ UITextField *_displayField;
+}
+
+-(void)viewDidLoad{
+ [super viewDidLoad];
+ self.view.frame = CGRectMake(0, 0, 235, 100);
+ self.view.backgroundColor = [UIColor whiteColor];
+
+ UIButton *btnClose = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 60, 30)];
+ [btnClose addTarget:self action:@selector(closeSelected:) forControlEvents:UIControlEventTouchUpInside];
+ [btnClose.titleLabel setFont:[UIFont boldSystemFontOfSize:12]];
+ [btnClose setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
+ [btnClose setTitle:@"Close" forState:UIControlStateNormal];
+ [self.view addSubview:btnClose];
+
+ UIButton *btnDone = [[UIButton alloc] initWithFrame:CGRectMake(170, 5, 60, 30)];
+ [btnDone addTarget:self action:@selector(doneSelected:) forControlEvents:UIControlEventTouchUpInside];
+ [btnDone.titleLabel setFont:[UIFont boldSystemFontOfSize:12]];
+ [btnDone setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
+ [btnDone setTitle:@"Done" forState:UIControlStateNormal];
+ [self.view addSubview:btnDone];
+
+ _urlField = [[UITextField alloc] initWithFrame:CGRectMake(5, 33, 225, 30)];
+ [_urlField setFont:[UIFont systemFontOfSize:12]];
+ [_urlField setPlaceholder:@"Skriv link her (http://)"];
+ [_urlField setBorderStyle:UITextBorderStyleLine];
+ [_urlField setAutocorrectionType:UITextAutocorrectionTypeNo];
+ [_urlField setAutocapitalizationType:UITextAutocorrectionTypeNo];
+ [self.view addSubview:_urlField];
+
+ _displayField = [[UITextField alloc] initWithFrame:CGRectMake(5, 65, 225, 30)];
+ [_displayField setFont:[UIFont systemFontOfSize:12]];
+ [_displayField setPlaceholder:@"Link beskrivelse her"];
+ [_displayField setBorderStyle:UITextBorderStyleLine];
+ [_displayField setAutocorrectionType:UITextAutocorrectionTypeNo];
+ [_displayField setAutocapitalizationType:UITextAutocorrectionTypeNo];
+ [self.view addSubview:_displayField];
+
+ [_urlField becomeFirstResponder];
+}
+
+- (void)doneSelected:(id)sender{
+ if([[_displayField text] isEqualToString:@""] || [[_displayField text] isEqualToString:@" "]){
+ [_displayField becomeFirstResponder];
+ return;
+ }
+
+ if([[_urlField text] isEqualToString:@""] || [[_urlField text] isEqualToString:@" "]){
+ [_urlField becomeFirstResponder];
+ return;
+ }
+
+ NSString *urlString = [self replaceURLWithLink:[_urlField text]];
+
+ [self.delegate richTextEditorInsertLinkViewControllerInsertURL:[NSURL URLWithString:urlString] withDisplayText:[_displayField text]];
+}
+- (void)closeSelected:(id)sender{
+ [self.delegate richTextEditorInsertLinkViewControllerDidCancel];
+}
+
+-(NSString*)replaceURLWithLink:(NSString*)text{
+ NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
+ NSArray* matches = [detector matchesInString:text options:0 range:NSMakeRange(0, [text length])];
+ NSString *retstring = text;
+ for (NSTextCheckingResult* result in [matches reverseObjectEnumerator]) {
+ NSString *match = [[result URL] absoluteString];
+ NSRange range = [result range];
+ retstring = [retstring stringByReplacingCharactersInRange:range withString:match];
+ }
+
+ return retstring;
+}
+
+@end
diff --git a/RichTextEditor/Source/RichTextEditorToolbar.h b/RichTextEditor/Source/RichTextEditorToolbar.h
index 7b84f13..b7ae4d8 100644
--- a/RichTextEditor/Source/RichTextEditorToolbar.h
+++ b/RichTextEditor/Source/RichTextEditorToolbar.h
@@ -53,7 +53,8 @@ typedef NS_ENUM(NSUInteger, RichTextEditorFeature) {
RichTextEditorFeatureTextForegroundColor = 1 << 11,
RichTextEditorFeatureParagraphIndentation = 1 << 12,
RichTextEditorFeatureParagraphFirstLineIndentation = 1 << 13,
- RichTextEditorFeatureAll = 1 << 14
+ RichTextEditorFeatureAll = 1 << 14,
+ RichTextEditorFeatureLink = 1 << 15
};
@protocol RichTextEditorToolbarDelegate
@@ -69,6 +70,7 @@ typedef NS_ENUM(NSUInteger, RichTextEditorFeature) {
- (void)richTextEditorToolbarDidSelectTextBackgroundColor:(UIColor *)color;
- (void)richTextEditorToolbarDidSelectTextForegroundColor:(UIColor *)color;
- (void)richTextEditorToolbarDidSelectTextAlignment:(NSTextAlignment)textAlignment;
+- (void)richTextEditorToolbarDidInsertLink:(NSURL*) link displayText:(NSString*)displayText;
@end
@protocol RichTextEditorToolbarDataSource
diff --git a/RichTextEditor/Source/RichTextEditorToolbar.m b/RichTextEditor/Source/RichTextEditorToolbar.m
index 7cc443d..a9328e7 100644
--- a/RichTextEditor/Source/RichTextEditorToolbar.m
+++ b/RichTextEditor/Source/RichTextEditorToolbar.m
@@ -31,6 +31,7 @@
#import "RichTextEditorFontSizePickerViewController.h"
#import "RichTextEditorFontPickerViewController.h"
#import "RichTextEditorColorPickerViewController.h"
+#import "RichTextEditorInsertLinkViewController.h"
#import "WEPopoverController.h"
#import "RichTextEditorToggleButton.h"
#import "UIFont+RichTextEditor.h"
@@ -39,7 +40,8 @@
#define ITEM_TOP_AND_BOTTOM_BORDER 5
#define ITEM_WITH 40
-@interface RichTextEditorToolbar()
+@interface RichTextEditorToolbar()
@property (nonatomic, strong) id popover;
@property (nonatomic, strong) RichTextEditorToggleButton *btnBold;
@property (nonatomic, strong) RichTextEditorToggleButton *btnItalic;
@@ -57,6 +59,7 @@ @interface RichTextEditorToolbar()
Date: Tue, 8 Jul 2014 10:55:31 +0200
Subject: [PATCH 08/10] Fixed warnings in WEPopoverController
---
RichTextEditor/Source/iphone Popover/WEPopoverController.m | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/RichTextEditor/Source/iphone Popover/WEPopoverController.m b/RichTextEditor/Source/iphone Popover/WEPopoverController.m
index 6f70626..4776028 100755
--- a/RichTextEditor/Source/iphone Popover/WEPopoverController.m
+++ b/RichTextEditor/Source/iphone Popover/WEPopoverController.m
@@ -46,6 +46,7 @@ - (id)init {
- (id)initWithContentViewController:(UIViewController *)viewController {
if ((self = [self init])) {
self.contentViewController = viewController;
+ self.popoverContentSize = viewController.view.frame.size;
}
return self;
}
@@ -138,7 +139,7 @@ - (void)presentPopoverFromRect:(CGRect)rect
[contentViewController view];
if (CGSizeEqualToSize(popoverContentSize, CGSizeZero)) {
- popoverContentSize = contentViewController.contentSizeForViewInPopover;
+ popoverContentSize = contentViewController.preferredContentSize;
}
CGRect displayArea = [self displayAreaForView:theView];
@@ -223,7 +224,7 @@ - (void)repositionPopoverFromRect:(CGRect)rect
}
if (CGSizeEqualToSize(popoverContentSize, CGSizeZero)) {
- popoverContentSize = contentViewController.contentSizeForViewInPopover;
+ popoverContentSize = contentViewController.preferredContentSize;
}
CGRect displayArea = [self displayAreaForView:theView];
From a74484bddd2c5e5735889aff9c486a705d6eb9f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Lilleb=C3=B8=20Holm?=
Date: Tue, 8 Jul 2014 10:56:11 +0200
Subject: [PATCH 09/10] - Added a more simple HTML string api for generating
very easily parsable HTML
---
.../NSAttributedString+RichTextEditor.h | 1 +
.../NSAttributedString+RichTextEditor.m | 65 +++++++++++++++++++
2 files changed, 66 insertions(+)
diff --git a/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.h b/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.h
index 423f99c..1d25b6f 100644
--- a/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.h
+++ b/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.h
@@ -33,5 +33,6 @@
- (NSRange)firstParagraphRangeFromTextRange:(NSRange)range;
- (NSArray *)rangeOfParagraphsFromTextRange:(NSRange)textRange;
- (NSString *)htmlString;
+- (NSString *)simpleHtmlString;
@end
diff --git a/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m b/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m
index b632340..d7aea6a 100644
--- a/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m
+++ b/RichTextEditor/Source/Categories/NSAttributedString+RichTextEditor.m
@@ -195,6 +195,71 @@ - (NSString *)htmlString
return htmlString;
}
+-(NSString *)simpleHtmlString{
+ NSMutableString *htmlString = [NSMutableString string];
+ NSArray *paragraphRanges = [self rangeOfParagraphsFromTextRange:NSMakeRange(0, self.string.length-1)];
+
+ for (int i=0 ; i"];
+
+
+ [self enumerateAttributesInRange:range
+ options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
+ usingBlock:^(NSDictionary *dictionary, NSRange range, BOOL *stop){
+
+ NSMutableString *fontString = [NSMutableString string];
+ UIFont *font = [dictionary objectForKey:NSFontAttributeName];
+ NSNumber *underline = [dictionary objectForKey:NSUnderlineStyleAttributeName];
+ BOOL hasUnderline = (!underline || underline.intValue == NSUnderlineStyleNone) ? NO :YES;
+ NSNumber *strikeThrough = [dictionary objectForKey:NSStrikethroughStyleAttributeName];
+ BOOL hasStrikeThrough = (!strikeThrough || strikeThrough.intValue == NSUnderlineStyleNone) ? NO :YES;
+ NSURL *url = [dictionary objectForKey:NSLinkAttributeName];
+
+ [fontString appendString:[[self.string substringFromIndex:range.location] substringToIndex:range.length]];
+
+ if(url){
+ [fontString insertString:[NSString stringWithFormat:@"",[url absoluteString]] atIndex:0];
+ [fontString insertString:@"" atIndex:fontString.length];
+ }
+
+ if ([font isBold])
+ {
+ [fontString insertString:@"" atIndex:0];
+ [fontString insertString:@"" atIndex:fontString.length];
+ }
+
+ if ([font isItalic])
+ {
+ [fontString insertString:@"" atIndex:0];
+ [fontString insertString:@"" atIndex:fontString.length];
+ }
+
+ if (hasUnderline)
+ {
+ [fontString insertString:@"" atIndex:0];
+ [fontString insertString:@"" atIndex:fontString.length];
+ }
+
+ if (hasStrikeThrough)
+ {
+ [fontString insertString:@"" atIndex:0];
+ [fontString insertString:@"" atIndex:fontString.length];
+ }
+
+
+ [htmlString appendString:fontString];
+ }];
+
+ [htmlString appendString:@"
"];
+ }
+
+ return htmlString;
+}
+
#pragma mark - Helper Methods -
- (NSString *)htmlTextAlignmentString:(NSTextAlignment)textAlignment
From f07527e9915fea9ae378c704f4ae0ede72bd2323 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20Lilleb=C3=B8=20Holm?=
Date: Tue, 8 Jul 2014 10:56:41 +0200
Subject: [PATCH 10/10] - Updated test view controller to contain the features
that have been tested
---
RichTextEditor/ViewController.m | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/RichTextEditor/ViewController.m b/RichTextEditor/ViewController.m
index a55fbaa..e944747 100644
--- a/RichTextEditor/ViewController.m
+++ b/RichTextEditor/ViewController.m
@@ -47,9 +47,13 @@ - (UIModalTransitionStyle)modalTransitionStyleForRichTextEditor:(RichTextEditor
return UIModalTransitionStyleFlipHorizontal;
}*/
+-(RichTextEditorToolbarPresentationStyle)presentationStyleForRichTextEditor:(RichTextEditor *)richTextEditor{
+ return RichTextEditorToolbarPresentationStylePopover;
+}
+
- (RichTextEditorFeature)featuresEnabledForRichTextEditor:(RichTextEditor *)richTextEditor
{
- return RichTextEditorFeatureFontSize | RichTextEditorFeatureFont | RichTextEditorFeatureAll;
+ return RichTextEditorFeatureLink | RichTextEditorFeatureItalic | RichTextEditorFeatureBold;
}
@end