ContentTableViewCell.m 2.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
//
//  ContentTableViewCell.m
//  Lighting
//
//  Created by 曹云霄 on 2016/12/9.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "ContentTableViewCell.h"
#import "STEmojiKeyboard.h"

@implementation ContentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self setUpToolView];
}

#pragma mark - ToolView
- (void)setUpToolView
{
    KeyBoardAccessoryView *toolView = [[KeyBoardAccessoryView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
    toolView.delegate = self;
    self.contentTextView.inputAccessoryView = toolView;
}

#pragma mark - Click
- (void)extensionButtonClick:(UIButton *)sender
{
    switch (sender.tag) {
        case Camera:
        {
            if ([self.delgate respondsToSelector:@selector(showCameraAction)]) {
                [self.delgate showCameraAction];
            }
        }
            break;
        case PhotoAlbum:
        {
            if ([self.delgate respondsToSelector:@selector(showPhotoAlbumAction)]) {
                [self.delgate showPhotoAlbumAction];
            }
        }
            break;
        case Emoji:
        {
            sender.selected = !sender.selected;
            if (sender.selected) {
                [[STEmojiKeyboard keyboard] setTextView:self.contentTextView];
            }else {
                [self.contentTextView setInputView:nil];
            }
            [self.contentTextView reloadInputViews];
            [self.contentTextView becomeFirstResponder];

        }
            break;
            
        default:
            break;
    }
}

#pragma mark - <UITextViewDelegate>
- (void)textViewDidEndEditing:(UITextView *)textView
{
    self.contentTextView.height = [self calculateStudyIntroductionHeight:textView.text];
    if ([self.delgate respondsToSelector:@selector(refreshHeight:)]) {
        [self.delgate refreshHeight:self.contentTextView.height];
    }
}

#pragma mark - 计算高度
- (CGFloat)calculateStudyIntroductionHeight:(NSString *)content
{
    CGSize s = [content boundingRectWithSize:CGSizeMake(ScreenWidth-40, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
    return s.height+20;
}














@end