BestReplyView.m 1.88 KB
Newer Older
曹云霄's avatar
曹云霄 committed
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
//
//  BestReplyView.m
//  Lighting
//
//  Created by 曹云霄 on 2016/12/13.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "BestReplyView.h"

@implementation BestReplyView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self uiConfigAction];
        [self addGestureRecognizer];
    }
    return self;
}

#pragma mark - UI
- (void)uiConfigAction
{
    self.backgroundColor = RGB(115, 116, 117, 1);
    self.layer.cornerRadius = 4.0f;
    self.layer.masksToBounds = YES;
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(5, 5, 20, 20);
    button.tag = 100;
    [button setImage:TCImage(@"best") forState:UIControlStateNormal];
    [button setImage:TCImage(@"bestselect") forState:UIControlStateSelected];
    [self addSubview:button];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 5, 50, 20)];
    label.text = @"最佳回复";
    label.tag = 101;
    label.font = [UIFont systemFontOfSize:12];
    label.textColor = [UIColor whiteColor];
    [self addSubview:label];
}

- (void)setIsBest:(BOOL)isBest
{
    _isBest = isBest;
    UIButton *button = [self viewWithTag:100];
    UILabel *label = [self viewWithTag:101];
    button.selected = _isBest;
    label.text = _isBest?@"取消最佳":@"设为最佳";
}

#pragma mark - 事件
- (void)addGestureRecognizer
{
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClickAction:)]];
}

#pragma mark - 响应
- (void)tapClickAction:(UITapGestureRecognizer *)sender
{
    if ([self.delegate respondsToSelector:@selector(tapClickAction:withReplyId:withIndexPath:)]) {
        UIButton *button = [self viewWithTag:100];
        [self.delegate tapClickAction:!button.isSelected withReplyId:self.replyId withIndexPath:self.indexPath];
    }
}

@end