新浪微博单元格自定义高度设置
来源:互联网 发布:sas 优化板块 编辑:程序博客网 时间:2024/06/05 15:42
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
const CGFloat fontSize =14.0f;
// 用户头部信息的高度
CGFloat height4Header = 40.0f;
// 微博原文所占的高度
CGFloat statusTextHeight = 0.0f;
// 原创微博附带的图片所占的高度
CGFloat statusImageViewHeight = 0.0f;
// 转发微博正文所占的高度
CGFloat reweetStatusTextHeight = 0.0f;
NSDictionary *statusInfo = self.statuesList[indexPath.section];
NSString *content = statusInfo[kStatusText];
statusTextHeight = [contentframeHeightWithFontSize:fontSize forViewWidth:310.0f];
NSDictionary *reweetStatus = statusInfo[kStatusRetweetStatus];
if (nil == reweetStatus ) {
//如果没有转发微博内容,则计算微博图片的大小
statusImageViewHeight = [selfheight4StatusImageView:statusInfo];
}else
{
NSString *retContent = reweetStatus[kStatusText];
reweetStatusTextHeight = [retContentframeHeightWithFontSize:fontSize forViewWidth:310.0f];
statusImageViewHeight = [selfheight4StatusImageView:reweetStatus];
}
return (height4Header + statusTextHeight + statusImageViewHeight + reweetStatusTextHeight +30);
}
//不管是微博正文还是转发微博,图片的高度设置都是一样的
- (CGFloat)height4StatusImageView:(NSDictionary*)dicStatuInfo
{
CGFloat statusImageViewHeight = 0.0f;
NSArray *picUrls = dicStatuInfo[kStatusPicUrls];
if (picUrls.count ==1) {
NSDictionary *dic = picUrls[0];
NSString *strPicUrl = dic[kStatusThumbnailPic];
//从新浪服务器以同步的方式下载图片数据
// NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:strPicUrl]];
// UIImage *image = [UIImage imageWithData:imageData];
CGSize size = [selfdownloadJpgImage:strPicUrl];
statusImageViewHeight += size.height;
}else
{
int picLineCount = ceil(picUrls.count / 3.0);
statusImageViewHeight += (80*picLineCount);
}
return statusImageViewHeight;
}
-(CGFloat)frameHeightWithFontSize:(CGFloat)fontsize forViewWidth:(CGFloat)width
{
//字符串的总宽度
NSDictionary *attributes =@{NSFontAttributeName: [UIFontsystemFontOfSize:fontsize]};
NSLog(@"attributes:%@",attributes);
CGSize size = [selfsizeWithAttributes:attributes];
//显示的行数
//每一行显示的字数,使用控件的宽度/字体的大小
NSUInteger wordsPerLine = floor(width/fontsize);//这样写为了让一行显示完整的字符串
//每一行显示宽度字体大小*每一行显示的字数
CGFloat widthPerLine = fontsize * wordsPerLine;
NSUInteger numLines = ceil(size.width / widthPerLine);
CGFloat height = numLines * size.height;
return height;
}
- 新浪微博单元格自定义高度设置
- 自定义cell的高度(新浪微博)
- xib自定义单元格的高度
- poi设置单元格宽高度
- 【新浪微博项目】07--设置navigationItem和自定义TitleButton
- 通过代码自定义cell(cell的高度不一致)实现新浪微博界面
- AlertDialog设置自定义高度
- Dialog设置自定义高度
- 自定义UITableViewCell新浪微博
- ext中设置datagrid单元格的高度
- POI设置单元格的宽度和高度
- UITableView设置单元格的高度的方法
- 单元格高度宽度几种设置
- 新浪微博如何自定义来源尾巴
- PC端自定义新浪微博尾巴
- PC端自定义新浪微博尾巴
- PC端自定义新浪微博尾巴
- PC端自定义新浪微博尾巴
- 基于ZooKeeper大规模集群配置系统概述
- Xcode6 相关问题
- Python知识总结
- 快速幂与矩阵—>快速矩阵幂
- iOS UITextView文字从顶部开始
- 新浪微博单元格自定义高度设置
- Python中list、tuple、dict区别
- Hibernate Tool slf4j 出错
- 关于在64位win7下运行Virtualbox安装系统时出错(提示VBoxDD.DLL错误)的解决方案(转)
- java容器之set
- iOS之UIButton设置
- 分支栏样式的圆角矩形的TextView
- java入门-成员变量的隐藏与方法重写(super)
- 心情日记