12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- //
- // YYTextCopyPasteExample.m
- // YYKitExample
- //
- // Created by ibireme on 15/9/12.
- // Copyright (c) 2015 ibireme. All rights reserved.
- //
- #import "YYTextCopyPasteExample.h"
- #import "YYText.h"
- #import "YYImage.h"
- #import "UIImage+YYWebImage.h"
- #import "UIView+YYAdd.h"
- #import "NSBundle+YYAdd.h"
- #import "NSString+YYAdd.h"
- #import "YYTextExampleHelper.h"
- @interface YYTextCopyPasteExample ()<YYTextViewDelegate>
- @property (nonatomic, assign) YYTextView *textView;
- @end
- @implementation YYTextCopyPasteExample
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
-
-
- NSString *text = @"You can copy image from browser or photo album and paste it to here. It support animated GIF and APNG. \n\nYou can also copy attributed string from other YYTextView.\n";
-
- YYTextSimpleMarkdownParser *parser = [YYTextSimpleMarkdownParser new];
- [parser setColorWithDarkTheme];
-
- YYTextView *textView = [YYTextView new];
- textView.text = text;
- textView.font = [UIFont systemFontOfSize:17];
- textView.size = self.view.size;
- textView.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
- textView.delegate = self;
- textView.allowsPasteImage = YES; /// Pasts image
- textView.allowsPasteAttributedString = YES; /// Paste attributed string
- if (kiOS7Later) {
- textView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
- }
- textView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
- textView.scrollIndicatorInsets = textView.contentInset;
- [self.view addSubview:textView];
- self.textView = textView;
-
- textView.selectedRange = NSMakeRange(text.length, 0);
- [textView becomeFirstResponder];
- }
- - (void)edit:(UIBarButtonItem *)item {
- if (_textView.isFirstResponder) {
- [_textView resignFirstResponder];
- } else {
- [_textView becomeFirstResponder];
- }
- }
- - (void)textViewDidBeginEditing:(YYTextView *)textView {
- UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
- target:self
- action:@selector(edit:)];
- self.navigationItem.rightBarButtonItem = buttonItem;
- }
- - (void)textViewDidEndEditing:(YYTextView *)textView {
- self.navigationItem.rightBarButtonItem = nil;
- }
- @end
|