IOS Yytext's use note one (Yytextview editor)

Source: Internet
Author: User
Tags uikit

Yytext is part of a powerful yykit that can be downloaded separately

GitHub Address: Https://github.com/ibireme/YYText

Powerful text framework for IOS to display and edit rich text.
(IT ' s a component of Yykit)

It is recommended to use Cocopod management when integrating


1. Inside the main two controls:

Yytextview and Yylabel

Now the main yytextview is simple to use

Yytext is mainly nsmutableattributedstring to deal with rich text his internal implementation can go deep into his own.

Simple text by side, using Nsmutableattributedstring to create an object and then appendattributesstring to stitch text and pictures (placeholder)

Directly on the code:

//  TextAndImageTextViewVC.h
//  Yytextdemo////
Created by Linpeng on  16/3/13.  copyright©2016 year Ibireme. All rights reserved.

#import <UIKit/UIKit.h>

@interface textandimagetextviewvc:uiviewcontroller

@end

TEXTANDIMAGETEXTVIEWVC.M//Yytextdemo////Created by Linpeng on 16/3/13. COPYRIGHT©2016 year Ibireme.
All rights reserved. #import "TextAndImageTextViewVC.h" #import "YYText.h" #import "Uiview+yyadd.h" #import "YYTextView.h" #import "Yyimag E.h "#import" Nsbundle+yyadd.h "#import" Nsstring+yyadd.h "@interface textandimagetextviewvc () @end Yytextview *textvie
W
    @implementation TEXTANDIMAGETEXTVIEWVC-(void) viewdidload {[Super viewdidload];

    
    [Self.view Setbackgroundcolor:[uicolor Whitecolor]];
    TextView = [[Yytextview alloc] Initwithframe:cgrectmake (0, 0, 0, 0)];
    textview.userinteractionenabled = YES;
    Textview.textverticalalignment = Yytextverticalalignmenttop;
    
    Textview.size = Cgsizemake (Self.view.frame.size.width, self.view.frame.size.height);
    Create the main attribute text nsmutableattributedstring *contenttext = [nsmutableattributedstring new];
    
    Uifont *font = [Uifont systemfontofsize:16]; Picture resources Yyimage *image = [YYImage imagenamed:@ "Demo.jpg"];
    
    Image.preloadallanimatedimageframes = YES; Add text + picture [ContentText appendattributedstring:[[nsattributedstring alloc] initwithstring:@ "This is the first stop picture" Attributes:nil]
    ];
        {Yyanimatedimageview *imageview = [[Yyanimatedimageview alloc] initwithimage:image];
        Imageview.frame = CGRectMake (0, 0, textview.width-10, textview.width/image.size.width*image.size.height); nsmutableattributedstring *attachtext = [nsmutableattributedstring yy_attachmentstringwithcontent:imageview Contentmode:uiviewcontentmodescaleaspectfit attachmentSize:imageView.size aligntofont:font Alignment:
        Yytextverticalalignmentcenter];
    [ContentText Appendattributedstring:attachtext]; //Add text + picture [ContentText appendattributedstring:[[nsattributedstring alloc] initwithstring:@ "\ n Next is the second one" attr
    
    Ibutes:nil]];
        
        {Yyanimatedimageview *imageview2 = [[Yyanimatedimageview alloc] initwithimage:image]; ImageView2. frame = CGRectMake (0, 0, textview.width-10, textview.width/image.size.width*image.size.height); nsmutableattributedstring *attachtext2 = [nsmutableattributedstring yy_attachmentstringwithcontent:imageview2 Contentmode:uiviewcontentmodescaleaspectfit attachmentSize:imageView2.size aligntofont:font Alignment:
        Yytextverticalalignmentcenter];
    [ContentText APPENDATTRIBUTEDSTRING:ATTACHTEXT2];
    } textview.attributedtext = ContentText;
    
    [Self.view Addsubview:textview];
    Get picture resources Nsarray *attachments = textView.textLayout.attachments;
        For (yytextattachment *attachment in attachments) {Yyanimatedimageview *imageview = attachment.content;
        Yyimage *image = (yyimage *) imageview.image;
    NSLog (@ "Get to Picture:%@", image);
    } Nsarray *attachmentranges = TextView.textLayout.attachmentRanges;
        For (Nsvalue *range in attachmentranges) {Nsrange r = [range Rangevalue]; NSLog (@ "Resource location:%ld length:%ld", R.location,R.length);
    }-(void) didreceivememorywarning {[Super didreceivememorywarning];
Dispose of any of the can is recreated. }/* #pragma mark-navigation//In a storyboard-based application, you'll often want to do a little preparation Re Navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller US
    ing [Segue Destinationviewcontroller].
Pass the selected object to the new view controller.
 } * * @end
The above code plus comments should be easy to understand without much attention. \ n the use of this line feed

See Effect Chart:

(Editable text + picture Some app needs to edit article function with this can be achieved in general, pictures and text have been acquired to the server after the corresponding upload, before no Yytextview also achieved this function, the effect is relatively poor, with this realization, quite perfect, Must give the Yytext author a compliment.










Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.