|
//
// SubCellFromAskForNews.m
// ThePaperBase
//
// Created by zhousan on 15/8/6.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "SubCellFromAskForNews.h"
@implementation SubCellFromAskForNews
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.anserNumsLabel.hidden = YES;
self.commentImg.hidden = YES;
self.attentionBtn.hidden = NO;
self.askContentLabel.textColor = [UIColor colorWithHexString:TextBlack];
[self.attentionBtn setTitleEdgeInsets:UIEdgeInsetsMake(6, 0, 4, 0)];
}
return self;
}
#pragma mark - menu tap handler
- (void)menuTap:(UIButton*)btn {
[self becomeFirstResponder];
// UIMenuItem *commentBack = [[UIMenuItem alloc] initWithTitle:@"回复"action:@selector(commentBack:)];
UIMenuItem *praise = [[UIMenuItem alloc] initWithTitle:@"回答"action:@selector(reply:)];
UIMenuItem *copy = [[UIMenuItem alloc] initWithTitle:@"复制"action:@selector(copyText:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObjects:praise, copy, nil]];
if (menu.menuVisible) {
[menu setMenuVisible:NO animated:YES];
return;
}
[menu setTargetRect:self.askContentLabel.frame inView:self];
[menu setMenuVisible:YES animated:YES];
}
#pragma mark - menuDelegate
- (BOOL)canBecomeFirstResponder{
[super canBecomeFirstResponder];
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
[super canPerformAction:action withSender:sender];
if (action == @selector(copyText:) || action == @selector(reply:))
{
return YES;
}
else
{
return NO;
}
}
- (void)setAnswNums:(NSString *)answNums {
self.topicNumsLabel.text = [NSString stringWithFormat:@"(%@个回答)",answNums];
}
- (void)reply:(id)sender {//回答
UIMenuController *menu = [UIMenuController sharedMenuController];
if (menu.menuVisible) {
[menu setMenuVisible:NO animated:YES];
}
if ([self.askFroNewDelegate respondsToSelector:@selector(replyBtnClick:)]) {
[self.askFroNewDelegate replyBtnClick:self.commentBO];
}
}
- (void)copyText:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = self.askContentLabel.text;
ShowMessage(@"复制成功", YES);
}
- (void)attentionBtnClick:(UIButton *)sender {
if ([self.askFroNewDelegate respondsToSelector:@selector(attentionBtnClick:withCell:)]) {
[self.askFroNewDelegate attentionBtnClick:sender withCell:self];
}
}
- (void)subLayoutSubViews {
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.left);
make.top.equalTo(self.top);
make.bottom.equalTo(self.bottom);
make.right.equalTo(self.right);
}];
[self.backBtn makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.backView);
}];
[self.answerIcon makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(10);
make.top.equalTo(self.backView.top).offset(7);
make.width.mas_equalTo(28);
make.height.mas_equalTo(28);
}];
[self.iconBack makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.answerIcon);
}];
[self.UserInfoBtn makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.answerIcon);
}];
[self.verifyTag makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(28);
make.top.equalTo(self.backView.top).offset(28);
make.height.mas_equalTo(12);
make.width.mas_equalTo(12);
}];
if (rect_screen.size.width == 320) {
[self.askAuthorLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(47);
make.top.equalTo(self.backView.top).offset(5);
make.height.mas_equalTo(14);
make.width.mas_equalTo(160);
}];
}else {
[self.askAuthorLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(47);
make.top.equalTo(self.backView.top).offset(5);
make.height.mas_equalTo(14);
make.width.mas_equalTo(210);
}];
}
[self.commentImg makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.right).offset(-45);
make.top.equalTo(self.backView.top).offset(23);
make.height.mas_equalTo(12);
make.width.mas_equalTo(12);
}];
[self.timeImg makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(48);
make.top.equalTo(self.backView.top).offset(25);
make.height.mas_equalTo(10);
make.width.mas_equalTo(10);
}];
[self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.timeImg.right).offset(5);
make.top.equalTo(self.askAuthorLabel.bottom).offset(7);
make.height.mas_equalTo(9);
make.width.mas_equalTo(100);
}];
// [self.askContentLabel makeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(self.backView.left).offset(10);
// make.top.equalTo(self.answerIcon.bottom).offset(10);
// make.height.mas_equalTo(0);
// make.right.equalTo(self.backView.right).offset(-10);
// }];
[self.lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left);
make.top.equalTo(self.askContentLabel.bottom).offset(14);
make.width.equalTo(self.backView.width);
make.height.mas_equalTo(0.5);
}];
[self.attentionBtn makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.askAuthorLabel.top).offset(5);
make.right.equalTo(self.backView.right).offset(-10);
make.height.mas_equalTo(20);
make.width.mas_equalTo(40);
}];
[self.topicNumsLabel makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.attentionBtn.left).offset(-5);
make.top.equalTo(self.attentionBtn.top).offset(3);
make.height.mas_equalTo(12);
make.width.mas_equalTo(70);
}];
[self.menuButton makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.askContentLabel);
}];
}
- (void)reLayoutSubViews {
CGFloat width = returnTextWidthWithRTLabel(self.anserNumsLabel.text, 10, appFont(8, NO), 0)+5;
__weak typeof(self) weakSelf = self;
[self.anserNumsLabel remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(weakSelf.backView.right).offset(-15);
make.top.equalTo(weakSelf.backView.top).offset(25);
make.height.mas_equalTo(9);
make.width.mas_equalTo(width);
}];
[self.askContentLabel remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(10);
make.top.equalTo(self.answerIcon.bottom).offset(10);
make.height.mas_equalTo(self.cellHeight);
make.right.equalTo(self.backView.right).offset(-10);
}];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
|