// Created by mac on 16/6/29.
// Copyright © 2016年 zcc. All rights reserved.
//
#import "HotCellHeight.h"
#import "UIViewExt.h"
#import "CommonalityH.h"
#define kTextWidth (kScreenWidth-20) //文字宽度
#define GAP 5
@implementation HotCellHeight
- (void)setHotModel:(HotModel *)hotModel{
_hotModel = hotModel;
//计算高度
[self countHeight];
}
#pragma mark 计算高度
- (void)countHeight{
CGFloat audiofloat = 0;
CGFloat imgfloat = 0;
CGFloat countHeight = 0;
_Height = 0;
//计算头像 位置
_avatarFrame = CGRectMake(GAP, GAP, 30, 30);
countHeight += _avatarFrame.size.height + GAP * 2 ;
//用户名称位置
_user_NameFrame = CGRectMake(CGRectGetMaxX(_avatarFrame)+GAP, GAP, kScreenWidth - 30 - GAP * 2, 30);
//计算线的位置
_wireFrame = CGRectMake(GAP, CGRectGetMaxY(_avatarFrame) + GAP,kScreenWidth - GAP*2 , 6);
countHeight += _wireFrame.size.height + GAP;
//计算图片位置
if(_hotModel.post_img == nil){
imgfloat = CGRectGetMaxY(_wireFrame);
}else{
_imgFrame = CGRectMake(GAP, CGRectGetMaxY(_wireFrame)+ GAP, kScreenWidth - GAP*2 ,kScreenWidth - GAP*2);
countHeight += _imgFrame.size.height + GAP;
imgfloat = CGRectGetMaxY(_imgFrame);
}
//计算文本位置
NSDictionary *dic = @{
NSFontAttributeName :
[UIFont fontWithName:@"FZLTCXHJW--GB1-0" size:15]
,
NSForegroundColorAttributeName :[UIColor blackColor]
};
CGSize maximumLabelSize = CGSizeMake(kTextWidth, 120);
CGRect zFrame = [_hotModel.content boundingRectWithSize:maximumLabelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
_contentFrame = CGRectMake(10, imgfloat + GAP, kTextWidth, zFrame.size.height);
countHeight += _contentFrame.size.height + GAP ;
//计算歌曲(背景)区域图片
if(_hotModel.post_audio == nil){
audiofloat = CGRectGetMaxY(_contentFrame);
}else{
_backAudioFrame = CGRectMake(GAP, CGRectGetMaxY(_contentFrame)+ GAP, kScreenWidth-GAP*2, 36);
//计算歌曲图片
_audioFrame = CGRectMake(GAP+3, CGRectGetMinY(_backAudioFrame)+3, 30, 30);
audiofloat = CGRectGetMaxY(_backAudioFrame);
countHeight += _backAudioFrame.size.height + GAP ;
//歌曲名称位置
_song_nameFrame = CGRectMake(CGRectGetMaxX(_audioFrame)+3, CGRectGetMinY(_backAudioFrame)+3,kScreenWidth - GAP + 3 + 3 + 30, 15);
_artistFrame = CGRectMake(CGRectGetMaxX(_audioFrame)+3, CGRectGetMinY(_backAudioFrame)+3 + 15, kScreenWidth - GAP + 3 + 3 + 30, 15);
_countSongFrame = CGRectMake(CGRectGetMaxX(_backAudioFrame) - 40, CGRectGetMinY(_backAudioFrame)+3, 40, 30);
_buttonLucencyFrame = _backAudioFrame;
}
//计算更新时间位置
_downFrame = CGRectMake(GAP*2, audiofloat + GAP, kScreenWidth/2, 20);
countHeight += _downFrame.size.height + GAP * 2;
//背景大小位置
_backFrame = CGRectMake(0, 0, kScreenWidth, countHeight);
_Height = countHeight;
//不计算高度 计算位置
CGFloat wfloat = kScreenWidth/7;
//点赞图片位置
_vote_countImgFrame = CGRectMake(wfloat * 4.0 , audiofloat + GAP, 20, 20);
//评论图片
_comment_countImgFrame = CGRectMake(wfloat * 5.0 , audiofloat + GAP, 20, 20);
//分享图片
_shareImgFrame = CGRectMake(wfloat * 6.0 +10 , audiofloat + GAP, 20, 20);
//点赞数量
_vote_countFrame = CGRectMake(wfloat * 4.0 +25 , audiofloat + GAP, 30, 20);
//评论数量
_comment_countFrame = CGRectMake(wfloat * 5.0 +25 , audiofloat + GAP, 30, 20);
}
@end
.h
// // Created by mac on 16/6/29. // Copyright © 2016年 zcc. All rights reserved. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "HotModel.h" @interface HotCellHeight : NSObject @property(nonatomic,assign)CGRect avatarFrame;//头像 @property(nonatomic,assign)CGRect wireFrame;//线 @property(nonatomic,assign)CGRect imgFrame;//700 @property(nonatomic,assign)CGRect contentFrame;//文本 @property(nonatomic,assign)CGRect audioFrame;//音乐图片高度 @property(nonatomic,assign)CGRect backAudioFrame;//区域音乐图片高度 @property(nonatomic,assign)CGRect downFrame;//更新时间 @property(nonatomic,assign)CGRect backFrame;//背景图片大小 @property(nonatomic,assign)CGFloat Height;//单元格总高度 @property(nonatomic,copy)HotModel *hotModel;//数据 @property(nonatomic,assign)CGRect user_NameFrame;//用户名 @property(nonatomic,assign)CGRect song_nameFrame;//歌名 @property(nonatomic,assign)CGRect artistFrame;//艺术家名称 @property(nonatomic,assign)CGRect countSongFrame;//歌曲数量 @property(nonatomic,assign)CGRect vote_countImgFrame;//点赞图片 @property(nonatomic,assign)CGRect comment_countImgFrame;//评论图片 @property(nonatomic,assign)CGRect shareImgFrame;//分享 @property(nonatomic,assign)CGRect vote_countFrame;//点赞数量 @property(nonatomic,assign)CGRect comment_countFrame;//评论数量 @property(nonatomic,assign)CGRect buttonLucencyFrame;//透明button的大小 @end