Git Product home page Git Product logo

secoretextview's Introduction

SECoreTextView License MIT

Version Platform Build Status Analytics

SECoreTextView is multi-line rich text view library with clickable links, selectable text, embedding images and editing.

Movie 1

Features

Multi-Line Rich text

iOS ScreenShot 1

Clickable hyper link

iOS ScreenShot 2

Embedding Images, Custom views, or Any blocks

iOS ScreenShot 8  iOS ScreenShot 9

Text selection

iOS ScreenShot 3  iOS ScreenShot 4  iOS ScreenShot 6

Copy & Paste

iOS ScreenShot 5

Editing (iOS only)

iOS ScreenShot 5

Both OS X / iOS supported

OS X ScreenShot 2

System Requirement

OS X 10.7(Lion) or later / iOS 5 or later

Installation

CocoaPods

pod 'SECoreTextView'

Manual Install

  1. git clone [email protected]:kishikawakatsumi/SECoreTextView.git
  2. Copy files in Lib and Resources to your project.
  3. Add CoreText.framework to your target.

License

SECoreTextView is available under the MIT license. See the LICENSE file for more info.

secoretextview's People

Contributors

bitdeli-chef avatar kishikawakatsumi avatar mingming1222 avatar nek023 avatar qmihara avatar ryohey avatar usami-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

secoretextview's Issues

Space will not wrap

Hi, Thank you for your development, saving me a lot of time, but I found any problems:
1, when I enter a space of continuous time, the editor does not wrap.
2, Sometimes when I insert a image, then wrap text, cursor height will not change. it same as image height.

SETextView with no (default) backgroundColor is not working correctly

In the iOS twitter example, I set the backgroundColor of the tweetTextView to default on MainStoryboard.storyboard. Then if you run it, the tweetTextView is not interacting with touches correctly. Looks like it's collapsed.

I don't know what is going on here, but it works correctly as long as you set the backgroundColor for the SETextView instance. So in my opinion, we should just leave it that way. But in case anybody else is in similar trouble, I posted this issue here.

i fixed the cursor position is incorrect when inserting a image or select a image from album.

Hi, Source contributors:

I referred to SECoreTextView in a my compay project, Thanks for your SECoreTextView, that is pretty library for edit.
but the cursor position is incorrect when inserting a image or select a image from album in my project and RichTextEditor project, so i fixed the bug, but i failed to push source code.

The following is my code
SECoreTextView.m:

  • (void)updateCaretPositionToNext:(NSInteger)currentCarePosition {
    if (!self.textLayout.textSelection) {
    self.textLayout.textSelection = [[SETextSelection alloc] init];
    }

    NSUInteger index = currentCarePosition + 1;
    if (index == NSNotFound || index >= self.text.length) {
    index = self.text.length;
    }
    if (self.text.length == 0) {
    index = 0;
    }

    self.caretView.frame = [self caretRectForPosition:[SETextPosition positionWithIndex:index]];

    [self.inputDelegate selectionWillChange:self];

    self.textLayout.markedTextRange = NSMakeRange(NSNotFound, 0);
    self.textLayout.textSelection.selectedRange = NSMakeRange(index, 0);
    [self selectionChanged];

    [self.inputDelegate selectionDidChange:self];
    }

  • (void)insertObject:(id)object size:(CGSize)size;
    {
    NSInteger index = self.selectedRange.location;
    NSRange selectedNSRange = self.textLayout.textSelection.selectedRange;
    SETextRange *markedTextRange = (SETextRange *)self.markedTextRange;
    NSRange markedTextNSRange;
    if (markedTextRange) {
    markedTextNSRange = markedTextRange.range;
    } else {
    markedTextNSRange = NSMakeRange(NSNotFound, 0);
    }

    SETextAttachment *attachment = nil;
    NSUInteger location = 0;
    if (markedTextRange && markedTextNSRange.location != NSNotFound) {
    location = markedTextNSRange.location;
    } else {
    location = selectedNSRange.location;
    }

    NSString *replacementCharacter = OBJECT_REPLACEMENT_CHARACTER;
    attachment = [[SETextAttachment alloc] initWithObject:object size:size range:NSMakeRange(location, replacementCharacter.length)];
    [self.attachments addObject:attachment];

    [self insertText:replacementCharacter];
    if (self.selectedRange.location != index + 1) {
    [self updateCaretPositionToNext:index];
    }
    }

thanks.
jeff

Cannot change selection when you drag form SESelectionGrabberDot

Hey I'm using your SECoreTextView. Its a great library. but it has this issue.
procedure,
1 - Enter some text
2 - Select them all
3 - Try to change selection from dragging SESelectionGrabberDot (its not working)

When you drag from caretView, Its working.
It would be really grateful if you fix this issue.
thank you.

use SETextView crash when insert Image

- (void)bubbleAttributtedStringWithText:(NSString *)text isSendingMessage:(BOOL)isSending withView:(SETextView *)textView {
    if (!text) {
        text = @"";
    }
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
    textView.attributedText = attributedString;
    UIFont *font = [UIFont systemFontOfSize:16.];

    NSString *regex_text = @"\\[[\u4e00-\u9fa5]+\\]";
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regex_text options:NSRegularExpressionCaseInsensitive error:NULL];
    NSArray *matches = [regex matchesInString:text options:NSMatchingReportCompletion range:NSMakeRange(0, attributedString.length)];
    if (matches.count < 1) {
        return;
    }

    CGSize imageSize = CGSizeMake(font.lineHeight, font.lineHeight);
    CGRect imageRect = CGRectMake(0, 0, imageSize.width, imageSize.height);
    NSDictionary *cnKeys  = [SFEmoticonManager sharedObject].objectCnKey;

    [textView removeAllAttributedText];
    for (NSTextCheckingResult *result in matches) {
        NSRange matchRange = result.range;

        NSString *placeholder = [text substringWithRange:matchRange];
        SFEmoticon *emoticon  = [cnKeys objectForKey:placeholder];
        if (!emoticon) {
            continue;
        }

        UIImage *image = [UIImage imageNamed:emoticon.imageName];
        UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0);
        [image drawInRect:imageRect];
        UIImage *newimage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        [textView addObject:newimage size:imageSize replaceRange:matchRange];
    }
}

when I use SETextView init and and run top code and ‘SETextView’ attribute ‘attachments’ init has spilth data.at last the APP crash this line:
NSAttributedString *originalAttributedString = [editingAttributedText attributedSubstringFromRange:attachment.range];

so I add method ‘[self.attachments removeAllObjects]’ the is ok .
I don’t know how?please help me

How to make SECoreTextView support language that have writing direction right to left (RTL) like Arabic

I have use SECoreTextView in my project. It's nice but my app want to support many languages (included language that have writing direction right to left (RTL) like Arabic).
The problem will happen when user switch beetween RTL language (e.g:Arabic) and Left to right (LTR) language (e.g:English) --> the cursor, text display and other behavior of SECoreTextView will be wrong.

My question is how to implement SECoreTextView support both RTL and LRT language?
What shoud I do ? I google for many days but every sample implemented UITextInput only support LTR language :(

iOS Does Not Compile Properly

There is code in CETextView.m (line 265 - color = [textColor createCGColor];) that calls a missing createCGColor member function from the SECompatibility UIColor category.

Here is a patch that fixes that compile error and allows the Demo to run properly (I am confused about attaching a patch):

diff --git a/Lib/SECompatibility.h b/Lib/SECompatibility.h
index 46b5cfd140320eb983794dcad24d7a07866acfc4..7f0d56ec0bc90692abd51c9cbe155397c3e1cf1e 100644
--- a/Lib/SECompatibility.h
+++ b/Lib/SECompatibility.h
@@ -29,8 +29,11 @@ extern NSString * const NSLinkAttributeName;

  • (UIColor *)selectedTextBackgroundColor;
  • (UIColor *)selectedMenuItemColor;

+- (CGColorRef)createCGColor;
+
@EnD

#else
#import <Cocoa/Cocoa.h>

diff --git a/Lib/SECompatibility.m b/Lib/SECompatibility.m
index 3dc01e8e5b82844e5110584f5a5927dc1487f7af..2fbd9552c5fa4b009b5ee1f8eb8da75ed7a3f69b 100644
--- a/Lib/SECompatibility.m
+++ b/Lib/SECompatibility.m
@@ -23,6 +23,11 @@ NSString * const NSLinkAttributeName = @"NSLink";
return [UIColor colorWithRed:0.286 green:0.549 blue:0.859 alpha:1.000];
}

+- (CGColorRef)createCGColor
+{

  • return CGColorCreateCopy(self.CGColor);
    +}

@EnD
#else
@implementation NSColor (Compatibility)

テキストのアライメントが反映されない

選択範囲を**寄せにするために以下のようにしてみましたが、反映されませんでした。

CTTextAlignment textAlignment = kCTTextAlignmentCenter;

CTParagraphStyleSetting setting[] = {
    { kCTParagraphStyleSpecifierAlignment, sizeof(textAlignment), &textAlignment},
    { kCTParagraphStyleSpecifierMinimumLineHeight, sizeof(lineHeight), &lineHeight },
    { kCTParagraphStyleSpecifierMaximumLineHeight, sizeof(lineHeight), &lineHeight },
    { kCTParagraphStyleSpecifierLineSpacing, sizeof(lineSpacing), &lineSpacing },
    { kCTParagraphStyleSpecifierMinimumLineSpacing, sizeof(lineSpacing), &lineSpacing },
    { kCTParagraphStyleSpecifierMaximumLineSpacing, sizeof(lineSpacing), &lineSpacing },
    { kCTParagraphStyleSpecifierParagraphSpacing, sizeof(paragraphSpacing), &paragraphSpacing }
};

CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(setting, sizeof(setting) / sizeof(CTParagraphStyleSetting));
[attributedString addAttributes:@{(id)kCTParagraphStyleAttributeName: (__bridge id)paragraphStyle} range:selectedRange];
CFRelease(paragraphStyle);

Hi kishikawakatsumi

I am kumar,

Its been good using the SECoreTextView, but i am facing a problem in reading the content,

I added Text and images to textview,but not able to read them as they are added like i added text first then image and again text so on..... Now when i access self.attributedText , i am getting only text but not the image info .can you please check it and return some id which contains the text and images as they are added rather than separating them like text and attachments... the order is missing for me if i am accessing separately. so thats y i am requesting you to return id which contains both in a single property as they are added.

crash

when app start,it crashed after get network info

Can't render only images in iOS 6

I want to render only images with SECoreTextView. I have an attributedString: *** (three * character without format) and and array images. I render these images using SECoreTextView with this helper method:

+(void) insertImageToTextView:(SETextView*)textView fromComponents:(RTComponents*) components {

    for (NSUInteger i = 0;  i < components.images.count; i++) {

        NSMutableDictionary* imageAttributes = [components.images objectAtIndex:i];

        UIImage* image = [UIImage imageNamed:imageAttributes[@"imgSrc"]];
        NSInteger imgIndex = [imageAttributes[@"imgIndex"] unsignedIntegerValue];

        if (image) {
            [textView addObject:image size:CGSizeMake(image.size.width, image.size.height) replaceRange:NSMakeRange(imgIndex, 1)];
        }
    }

}

Add Image to textview

    [SETextViewHelper insertImageToTextView:seTextView fromComponents:data];
//attributedString is ***
    [richTextView setAttributedText:[SETextViewHelper attributedStringFromComponents:attributedString]];

IOS 7, everything is OK but in iOS 6 the problem is SETextLayout will return wrong number line of CTFrame (in this case CTFrameGetLines(_frame) return 0) so no thing is rendered.
I can fix this by using the trick that append original attributedString with an character (any character, in my case is space character) and do the same thing above. After do this trick, all images will be rendered and everything is fine.

This issue is something happened like this:
http://stackoverflow.com/questions/18703672/ios-method-ctframegetlines-return-empty-array

Please see these images for more details:

Resut with origin String ***

Result after do a trick, orginStr with append space character at the end

Retain cycle in SETextEditingCaret

Problem:
SETextEditingCaret is retained by its property blinkTimer and will never be deallocated.
This may eventually lead to the application consuming 100% of CPU.

How to fix it:

  1. Move @property (nonatomic) NSTimer *blinkTimer; to SETextEditingCaret.h
  2. Add [_caretView.blinkTimer invalidate]; to SETextView's dealloc

How can i display richtext with image?

i found if i use UITextView or UILabel, i can use UITextView.attributedText = my attributedString; to display image.
but i use SECoreTextView.attributedText = my attributedString, it only display text, but image could not display, why, how can i do? thanks.

skynetbird

UITextAttributeTextColor setting in attributedText is not respected on iOS6

Hi,

I may find a bug which only appears on iOS6 (may on iOS5 as well).

On iOS6, setting attributedText with NSAttributedString that has UITextAttributeTextColor attribute has no effect. The text is still displayed in black.

In order to display text in custom color and font on iOS6, font and textColor ivar must be both set.

Regards,

textViewDidEndSelecting of delegate is not called.

初めまして。
CocoaPodsやiOS5への対応がありがたく、
利用させていただいています。

件名で書かせていただいた通り、
DelegateのtextViewDidEndSelectionが呼び出されません。
一方で、textViewDidChangeSelectionは呼び出されています。

恐らく、finishSelectingメソッドにおいて、
自クラスにてrespondsToSelectorを呼び出していることが問題だと思われます。
File: SETextView.h, Line: 529~543

- (void)finishSelecting
{
#if TARGET_OS_IPHONE
    if (!self.editing) {
        if (self.showsEditingMenuAutomatically) {
            [self hideEditingMenu];
            [self showEditingMenu];
        }
    }
#endif

    if ([self respondsToSelector:@selector(textViewDidEndSelecting:)]) {
        [self.delegate textViewDidEndSelecting:self];
    }
}

勝手ながら、改善案を示させていただきますと、
次のようになるのではないでしょうか。
File: SETextView.h, Line: 540

    if ([self.delegate respondsToSelector:@selector(textViewDidEndSelecting:)]) {

the "paragraphSpacing" calculate is error when "paragraphSpacing" has a value

the "paragraphSpacing" calculate when "paragraphSpacing" has a value,

example:
paragraphSpacing = 15
text = @" 迷住我的是大气的车头,华丽的车身线条,鲜亮妖娆的勺型尾灯。2012年12月30日下个性订单,6月10日到,11日提车,呵护全家的大白鲨般冰川白Q7TDI,2012年,该如何记录与Q7的邂逅呢?\n 迷住我的是大气的车头,华丽的车身线条,鲜亮妖娆的勺型尾灯。2012年12月30日下个性订单,6月10日到,11日提车,呵护全家的大白鲨般冰川白Q7TDI,2012年,该如何记录与Q7的邂逅呢?"

Issue in recognize the text & added image from the textview .

I want to save the text & in between added image data in to my database. how i do this ? right now i am getting the NSAttributed string but i don't want that. it's to big data for me to save in to DB or pass to server. is there any other way to i get the solution ?

set font issue on iOS5

i set font with system font, but it look like as bold font:

UIFont *font = [UIFont systemFontOfSize:14];
CTFontRef fontRef = CTFontCreateWithName((__bridge CFStringRef)font.fontName, font.pointSize, NULL);
id ctfont = (__bridge id)(fontRef);
_defaultAttributes = @{(id)kCTForegroundColorAttributeName: (id)[UIColor colorWithHexString:@"#474747"].CGColor, (id)kCTFontAttributeName: ctfont};

-2

when SETextView not call sizeToFit,layout is error

example:
SETextView frame is {300,91},
params cell.seTextView.text = article.content;
cell.seTextView.lineBreakMode = NSLineBreakByTruncatingTail;
// cell.seTextView.lineSpacing = 5;
cell.seTextView.font = [UIFont systemFontOfSize:15];
cell.seTextView.textColor = [UIColor colorWithRed:100/255.f green:100/255.f blue:100/255.f alpha:1.0f];
// cell.seTextView.paragraphSpacing = 15;

text: Just over 5 lines in English or Chinese characters, layout error occurs.
qq20140321-1

Word wrap with ellipsis truncation

Hi, sorry for another issue but this is really requesting advice. In my app I need to show a 2 line wrapped label with ellipsis truncation on the second line if needed. I was able to do this with a Mac NSTextField but it has poor performace. Is there any simple way to achieve the same effect with SETextView? Is there a way to calculate space needed for an ellipsis and remove characters and then draw one or something like that?

Here is an example of where I need truncation: https://www.dropbox.com/s/8k3tdnzjvgty775/Screenshot%202013-10-27%2021.33.56.png

テキストを斜体で表示できない

文字を斜体で表示しようとして以下のように指定してみましたが反映されませんでした。
(NSObliquenessAttributeName は iOS 7 以降ですが・・・)

[attributedString addAttribute:NSObliquenessAttributeName value:@(obliqueness) range:selectedRange];

テキストに打ち消し線をつけることができない

打ち消し線をつけるために以下のように NSAttributedString に属性を追加してみましたが、つけることができませんでした。

        [attributedString addAttribute:NSStrikethroughStyleAttributeName value:@(kCTUnderlineStyleSingle) range:selectedRange];

How to export HTML

after i edit and input some image,how could i export it to HTML string?

音声入力を使ったとき特定の操作でクラッシュする

サンプルの RichTextEditor で、以下の操作で発生します。

環境

iPhone 5、iOS 7.1.2

操作手順

  1. テキストエリアをタップする。
  2. ソフトウェアキーボードの音声入力ボタンを押し、なにも入力せずに完了する。
    • このとき、何も入力していないはずなのにいくつかの空白が挿入されたように見えます。
  3. 挿入された空白を削除する。
  4. 右上のDoneボタンを押す。
    • このとき、アプリがクラッシュします。
*** Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds'

Link Detection

Does this library support automatic link detection for urls, emails, phone numbers like TTTAttributedLabel?

iOS5: Crash at accessing to NSLinkAttributeName

iOS5(simulator)NSLinkAttributeName

error: use of undeclared identifier 'NSLinkAttributeName'

SETextLayout.m

- (void)detectLinks
{
    NSMutableArray *links = [[NSMutableArray alloc] init];

    NSUInteger length = self.attributedString.length;
    [self.attributedString enumerateAttribute:NSLinkAttributeName
                                      inRange:NSMakeRange(0, length)
                                      options:0
                                   usingBlock:^(id value, NSRange range, BOOL *stop)
     {
         if (value) {
             NSString *linkText = [self.attributedString.string substringWithRange:range];
             SELinkText *link = [[SELinkText alloc] initWithText:linkText object:value range:range];
             [links addObject:link];
         }
     }];

    _links = [links copy];
}

bug of this library?Contact [email protected] input only showing "contact"

HI,
When I am using this library and input string "Contact [email protected]" but only the output is
"Contact ". All the string are missing after "contact " and using empty instead. What would be the possible reason?

if (!_displayTextView) { SETextView *displayTextView = [[SETextView alloc] initWithFrame:CGRectZero]; displayTextView.textColor = [UIColor colorWithWhite:0.143 alpha:1.000]; displayTextView.backgroundColor = [UIColor clearColor]; displayTextView.selectable = NO; displayTextView.lineSpacing = kXHTextLineSpacing; displayTextView.font = [[XHMessageBubbleView appearance] font]; displayTextView.showsEditingMenuAutomatically = NO; displayTextView.highlighted = NO; [self addSubview:displayTextView]; _displayTextView = displayTextView; }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.