|
//
// ImageShareController.m
// ThePaperBase
//
// Created by YoungLee on 15/11/10.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "ImageShareController.h"
#import "TPEmojiLabel.h"
@interface ImageShareController(){
CGFloat topicHieght;
CGFloat askHeight;
CGFloat answerNameWidth;
CGFloat answerHeight;
}
@property(nonatomic, strong)UIImageView *logoImg;
@property(nonatomic, strong)UILabel *topicLabel;
@property(nonatomic, strong)UIView *labelView;
@property(nonatomic, strong)UILabel *askNameLabel;
@property(nonatomic, strong)TPEmojiLabel *askLabel;
@property(nonatomic, strong)UILabel *answerNameLabel;
@property(nonatomic, strong)UILabel *hostLabel;
@property(nonatomic, strong)UILabel *answerDot;
@property(nonatomic, strong)UIImageView *tizhuIcon;
@property(nonatomic, strong)TPEmojiLabel *answerLabel;
@property(nonatomic, strong)UIView *bottomLine;
@property(nonatomic, strong)UILabel *shareLabel;
@property(nonatomic, strong)UIView *borderView;
@end
@implementation ImageShareController
-(instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[self addSubview:self.borderView];
[self.borderView addSubview:self.logoImg];
[self.borderView addSubview:self.labelView];
[self.borderView addSubview:self.topicLabel];
// [self.borderView addSubview:self.firstLine];
[self.borderView addSubview:self.askNameLabel];
[self.borderView addSubview:self.askLabel];
[self.borderView addSubview:self.answerNameLabel];
[self.borderView addSubview:self.hostLabel];
[self.borderView addSubview:self.answerDot];
[self.borderView addSubview:self.tizhuIcon];
[self.borderView addSubview:self.answerLabel];
[self.borderView addSubview:self.bottomLine];
[self.borderView addSubview:self.shareLabel];
// self.topicLabel.backgroundColor = RandomColor;
// self.askNameLabel.backgroundColor = RandomColor;
// self.askLabel.backgroundColor = RandomColor;
// self.answerLabel.backgroundColor = [UIColor greenColor];
// self.answerNameLabel.backgroundColor = RandomColor;
}
return self;
}
-(void)setAskData:(commentObjectVO *)askData{
self.answerNameLabel.hidden = YES;
self.answerLabel.hidden = YES;
self.answerDot.hidden = YES;
self.hostLabel.hidden = YES;
self.tizhuIcon.hidden = YES;
self.topicLabel.text = askData.contName;
topicHieght = heightForString(self.topicLabel.text, self.topicLabel.font, 170, NSLineBreakByWordWrapping);
userBO *askUser = setJsonDicToDataModel(askData.userInfo, [userBO class]);
self.askNameLabel.text = [NSString stringWithFormat:@"澎友【%@】:",askUser.sname];
self.askLabel.attributedText = getLineSpaceAttributedString(askData.content, 6, appFont(TEXT_FIVE_LEVELSIZE, NO));
askHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(askData.content, 6, appFont(TEXT_FIVE_LEVELSIZE, NO)), 170, appFont(TEXT_FIVE_LEVELSIZE, NO));
self.shareLabel.text = @"分享自澎湃新闻";
[self setAskLayout];
}
-(void)setAskData:(commentObjectVO *)askData answerData:(commentObjectVO *)answerData hostId:(NSString *)hostId topHeight:(CGFloat)topHeight askHeight:(CGFloat)askHei answerHeight:(CGFloat)answerHei{
topicHieght = topHeight;
askHeight = askHei;
answerHeight = answerHei;
NSAttributedString *topicStr = [[NSAttributedString alloc]init];
if ([askData.objectType intValue] == 3) {
topicStr = getLineSpaceAttributedString([NSString stringWithFormat:@"话题:%@",askData.contName], 3, self.topicLabel.font);
}else{
topicStr = getLineSpaceAttributedString([NSString stringWithFormat:@"原新闻:%@",askData.contName], 3, self.topicLabel.font);
}
self.topicLabel.attributedText = topicStr;
userBO *askUser;
NSAttributedString *askStr = [[NSAttributedString alloc]init];
NSAttributedString *answerStr = [[NSAttributedString alloc]init];
if (askData.parentInfo) {
askUser = setJsonDicToDataModel(askData.parentInfo[@"userInfo"], [userBO class]);
self.askNameLabel.text = [NSString stringWithFormat:@"澎友【%@】:",askUser.sname];
askStr = getLineSpaceAttributedString(askData.parentInfo[@"content"], 6, self.askLabel.font);
}else{
askUser = setJsonDicToDataModel(askData.userInfo, [userBO class]);
self.askNameLabel.text = [NSString stringWithFormat:@"澎友【%@】:",askUser.sname];
askStr = getLineSpaceAttributedString(askData.content, 6,self.askLabel.font);
}
self.askLabel.attributedText = askStr;
userBO *answerUser = setJsonDicToDataModel(answerData.userInfo, [userBO class]);
self.answerNameLabel.text = answerUser.sname;
answerNameWidth = widthForString(self.answerNameLabel.text, self.answerNameLabel.font, 20, NSLineBreakByWordWrapping);
answerStr = getLineSpaceAttributedString(answerData.content, 6, self.answerLabel.font);
self.answerLabel.attributedText = answerStr;
if ([answerData.objectType intValue] == 3) {
self.shareLabel.text = @"分享自澎湃问吧";
if ([answerUser.userId intValue] == [hostId intValue]) {
self.hostLabel.hidden = NO;
}else{
self.hostLabel.hidden = YES;
}
}else{
self.shareLabel.text = @"分享自澎湃新闻";
self.hostLabel.hidden = YES;
}
answerNameWidth = 5+widthForString(self.answerNameLabel.text, self.answerNameLabel.font, answerHeight, self.answerNameLabel.lineBreakMode);
if (answerNameWidth > 160) {
answerNameWidth = 160;
}
[self setLayout];
}
-(void) setAskData:(commentObjectVO *)askData answerData:(commentObjectVO*) answerData hostId:(NSString*)hostId topHeight:(CGFloat) topHeight askStr:(NSString*) askStr askHeight:(CGFloat) askHei answerStr:(NSString*)answerStr answerHeight:(CGFloat) answerHei{
topicHieght = topHeight;
askHeight = askHei;
answerHeight = answerHei;
NSAttributedString *topicStr = [[NSAttributedString alloc]init];
if ([askData.objectType intValue] == 3) {
topicStr = getLineSpaceAttributedString([NSString stringWithFormat:@"话题:%@",askData.contName], 3, self.topicLabel.font);
}else{
topicStr = getLineSpaceAttributedString([NSString stringWithFormat:@"原新闻:%@",askData.contName], 3, self.topicLabel.font);
}
self.topicLabel.attributedText = topicStr;
userBO *askUser;
if (askData.parentInfo) {
askUser = setJsonDicToDataModel(askData.parentInfo[@"userInfo"], [userBO class]);
self.askNameLabel.text = [NSString stringWithFormat:@"澎友【%@】:",askUser.sname];
// askStr = getLineSpaceAttributedString(askData.parentInfo[@"content"], 6, self.askLabel.font);
}else{
askUser = setJsonDicToDataModel(askData.userInfo, [userBO class]);
self.askNameLabel.text = [NSString stringWithFormat:@"澎友【%@】:",askUser.sname];
// askStr = getLineSpaceAttributedString(askData.content, 6,self.askLabel.font);
}
self.askLabel.attributedText = getLineSpaceAttributedString(askStr, 6,self.askLabel.font);;
userBO *answerUser = setJsonDicToDataModel(answerData.userInfo, [userBO class]);
self.answerNameLabel.text = answerUser.sname;
answerNameWidth = widthForString(self.answerNameLabel.text, self.answerNameLabel.font, 20, NSLineBreakByWordWrapping);
// answerStr = getLineSpaceAttributedString(answerData.content, 6, self.answerLabel.font);
self.answerLabel.attributedText = getLineSpaceAttributedString(answerStr, 6, self.answerLabel.font);
if ([answerData.objectType intValue] == 3) {
self.shareLabel.text = @"分享自澎湃问吧";
if ([answerUser.userId intValue] == [hostId intValue]) {
self.hostLabel.hidden = NO;
}else{
self.hostLabel.hidden = YES;
}
}else{
self.shareLabel.text = @"分享自澎湃新闻";
self.hostLabel.hidden = YES;
}
answerNameWidth = 5+widthForString(self.answerNameLabel.text, self.answerNameLabel.font, answerHeight, self.answerNameLabel.lineBreakMode);
if (answerNameWidth > 160) {
answerNameWidth = 160;
}
[self setLayout];
}
-(void) setAskData:(commentObjectVO *)askData answerData:(commentObjectVO*) answerData hostId:(NSString*)hostId topStr:(NSString*) str topHeight:(CGFloat) topHeight askStr:(NSString*) askStr askHeight:(CGFloat) askHei answerStr:(NSString*)answerStr answerHeight:(CGFloat) answerHei{
topicHieght = topHeight;
askHeight = askHei;
answerHeight = answerHei;
NSAttributedString *topicStr = [[NSAttributedString alloc]init];
if ([askData.objectType intValue] == 3) {
topicStr = getLineSpaceAttributedString([NSString stringWithFormat:@"话题:%@",askData.contName], 3, self.topicLabel.font);
}else{
topicStr = getLineSpaceAttributedString([NSString stringWithFormat:@"原新闻:%@",askData.contName], 3, self.topicLabel.font);
}
self.topicLabel.attributedText = topicStr;
userBO *askUser;
if (askData.parentInfo) {
askUser = setJsonDicToDataModel(askData.parentInfo[@"userInfo"], [userBO class]);
self.askNameLabel.text = [NSString stringWithFormat:@"澎友【%@】:",askUser.sname];
// askStr = getLineSpaceAttributedString(askData.parentInfo[@"content"], 6, self.askLabel.font);
}else{
askUser = setJsonDicToDataModel(askData.userInfo, [userBO class]);
self.askNameLabel.text = [NSString stringWithFormat:@"澎友【%@】:",askUser.sname];
// askStr = getLineSpaceAttributedString(askData.content, 6,self.askLabel.font);
}
self.askLabel.attributedText = getLineSpaceAttributedString(askStr, 6,appFont(TEXT_FIVE_LEVELSIZE, NO));
userBO *answerUser = setJsonDicToDataModel(answerData.userInfo, [userBO class]);
self.answerNameLabel.text = answerUser.sname;
answerNameWidth = widthForString(self.answerNameLabel.text, self.answerNameLabel.font, 20, NSLineBreakByWordWrapping);
// answerStr = getLineSpaceAttributedString(answerData.content, 6, self.answerLabel.font);
self.answerLabel.attributedText = getLineSpaceAttributedString(answerStr, 6, self.answerLabel.font);
if ([answerData.objectType intValue] == 3) {
self.shareLabel.text = @"分享自澎湃问吧";
if ([answerUser.userId intValue] == [hostId intValue]) {
self.hostLabel.hidden = NO;
}else{
self.hostLabel.hidden = YES;
}
}else{
self.shareLabel.text = @"分享自澎湃新闻";
self.hostLabel.hidden = YES;
}
answerNameWidth = 5+widthForString(self.answerNameLabel.text, self.answerNameLabel.font, answerHeight, self.answerNameLabel.lineBreakMode);
if (answerNameWidth > 160) {
answerNameWidth = 160;
}
[self setLayout];
}
#pragma mark -- set View
-(UIImageView *)logoImg{
if (!_logoImg) {
_logoImg = [UIImageView new];
_logoImg.image = Image(@"other/imageShare_logo.png");
}
return _logoImg;
}
-(UIView *)labelView{
if (!_labelView) {
_labelView = [UIView new];
_labelView.backgroundColor = [UIColor colorWithHexString:@"0xE5B45A"];
}
return _labelView;
}
-(UILabel *)topicLabel{
if (!_topicLabel) {
_topicLabel = [UILabel new];
_topicLabel.textColor = [UIColor colorWithHexString:TextLightGray];
_topicLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_topicLabel.lineBreakMode = NSLineBreakByCharWrapping;
_topicLabel.numberOfLines = 0;
}
return _topicLabel;
}
-(UILabel *)askNameLabel{
if (!_askNameLabel) {
_askNameLabel = [UILabel new];
_askNameLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_askNameLabel.textColor = [UIColor colorWithHexString:TextLightGray];
_askNameLabel.numberOfLines = 0;
}
return _askNameLabel;
}
-(TPEmojiLabel *)askLabel{
if (!_askLabel) {
_askLabel = [[TPEmojiLabel alloc] initWithFrame:CGRectMake(0, 0, 170, 0) LineSpace:6 ParagraphSpacing:0];
_askLabel.textAlignment = NSTextAlignmentLeft;
_askLabel.lineBreakMode = NSLineBreakByWordWrapping;
_askLabel.textColor = [UIColor colorWithHexString:TextGray];
_askLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
}
return _askLabel;
}
-(UILabel *)answerNameLabel{
if (!_answerNameLabel) {
_answerNameLabel = [UILabel new];
_answerNameLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_answerNameLabel.textColor = [UIColor colorWithHexString:TextLightGray];
_answerNameLabel.numberOfLines = 0;
}
return _answerNameLabel;
}
- (UILabel *)hostLabel {
if (!_hostLabel) {
_hostLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 32, 20)];
_hostLabel.text = @"题主";
_hostLabel.textAlignment = NSTextAlignmentCenter;
_hostLabel.backgroundColor = [UIColor colorWithHexString:@"0xec1c24"];
_hostLabel.textColor = [UIColor whiteColor];
_hostLabel.layer.masksToBounds = YES;
_hostLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_hostLabel.hidden = YES;
}
return _hostLabel;
}
-(UILabel *)answerDot{
if (!_answerDot) {
_answerDot = [UILabel new];
_answerDot.textColor = [UIColor colorWithHexString:TextLightGray];
_answerDot.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
_answerDot.text = @":";
}
return _answerDot;
}
-(TPEmojiLabel *)answerLabel{
if (!_answerLabel) {
_answerLabel = [[TPEmojiLabel alloc] initWithFrame:CGRectMake(0, 0, 170, 0) LineSpace:10 ParagraphSpacing:0];
_answerLabel.textAlignment = NSTextAlignmentLeft;
_answerLabel.lineBreakMode = NSLineBreakByWordWrapping;
_answerLabel.textColor = [UIColor colorWithHexString:TextGray];
_answerLabel.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
}
return _answerLabel;
}
-(UIView *)bottomLine{
if (!_bottomLine) {
_bottomLine = [UIView new];
_bottomLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _bottomLine;
}
-(UILabel *)shareLabel{
if (!_shareLabel) {
_shareLabel = [UILabel new];
_shareLabel.textColor = [UIColor colorWithHexString:TextBlack];
_shareLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_shareLabel.textAlignment = NSTextAlignmentCenter;
}
return _shareLabel;
}
-(UIView *)borderView{
if (!_borderView) {
_borderView = [UIView new];
_borderView.backgroundColor = [UIColor clearColor];
_borderView.layer.borderWidth = 1;
_borderView.layer.borderColor = [UIColor colorWithHexString:LINECOLOR].CGColor;
}
return _borderView;
}
-(void) setAskLayout{
self.borderView.frame = CGRectMake(7, 7, CGRectGetWidth(self.bounds)-14, CGRectGetHeight(self.bounds)-14);
self.logoImg.frame = CGRectMake(CGRectGetWidth(self.borderView.frame)/2-65/2, 23, 65, 38);
topicHieght = [self.topicLabel sizeThatFits:CGSizeMake(160, CGFLOAT_MAX)].height;
self.labelView.frame = CGRectMake(24, CGRectGetMaxY(self.logoImg.frame)+60, 2, topicHieght);
self.topicLabel.frame = CGRectMake(CGRectGetMaxX(self.labelView.frame)+7, CGRectGetMaxY(self.logoImg.frame)+60, 160, topicHieght);
self.askNameLabel.frame = CGRectMake(24, CGRectGetMaxY(self.topicLabel.frame)+35, 170, 20);
// askHeight = [self.askLabel sizeThatFits:CGSizeMake(170, CGFLOAT_MAX)].height;
self.askLabel.frame = CGRectMake(24, CGRectGetMaxY(self.askNameLabel.frame)+15, 170, askHeight);
self.bottomLine.frame = CGRectMake(24, CGRectGetMaxY(self.borderView.frame)-33, CGRectGetWidth(self.borderView.frame)-50, 0.5);
self.shareLabel.frame = CGRectMake(24, CGRectGetMaxY(self.borderView.frame)-30, CGRectGetWidth(self.borderView.frame)-50, 20);
}
-(void)setLayout{
//14 50
self.borderView.frame = CGRectMake(7, 7, CGRectGetWidth(self.bounds)-14, CGRectGetHeight(self.bounds)-14);
self.logoImg.frame = CGRectMake(CGRectGetWidth(self.borderView.frame)/2 -65/2, 23, 65, 38);
self.labelView.frame = CGRectMake(25, CGRectGetMaxY(self.logoImg.frame)+50, 2, topicHieght);
self.topicLabel.frame = CGRectMake(CGRectGetMaxX(self.labelView.frame)+7, CGRectGetMaxY(self.logoImg.frame)+50, 160, topicHieght);
self.askNameLabel.frame = CGRectMake(25, CGRectGetMaxY(self.topicLabel.frame)+25, 170, 20);
// askHeight = [self.askLabel sizeThatFits:CGSizeMake(170, CGFLOAT_MAX)].height;
self.askLabel.frame = CGRectMake(25, CGRectGetMaxY(self.askNameLabel.frame)+15, 170, askHeight);
self.answerNameLabel.frame = CGRectMake(25, CGRectGetMaxY(self.askLabel.frame)+30,answerNameWidth, 20);
if (self.hostLabel.hidden) {
self.answerDot.frame = CGRectMake(CGRectGetMaxX(self.answerNameLabel.frame)+5, CGRectGetMinY(self.answerNameLabel.frame), 20, 20);
}else{
self.hostLabel.frame = CGRectMake(CGRectGetMaxX(self.answerNameLabel.frame)+7, CGRectGetMinY(self.answerNameLabel.frame), 32, 20);
self.answerDot.frame = CGRectMake(CGRectGetMaxX(self.hostLabel.frame)+5, CGRectGetMinY(self.answerNameLabel.frame), 20, 20);
}
answerHeight = [self.answerLabel sizeThatFits:CGSizeMake(170, CGFLOAT_MAX)].height;
self.answerLabel.frame = CGRectMake(25, CGRectGetMaxY(self.answerNameLabel.frame)+15, 170, answerHeight);
self.bottomLine.frame = CGRectMake(25, CGRectGetMaxY(self.answerLabel.frame)+60, CGRectGetWidth(self.borderView.frame)-50, 0.5);
self.shareLabel.frame = CGRectMake(25, CGRectGetMaxY(self.bottomLine.frame)+5, CGRectGetWidth(self.borderView.frame)-50, 20);
}
@end
|