IOS---UITableViewCell自适应行高(非AutoLayout)
来源:互联网 发布:魔方大数据 编辑:程序博客网 时间:2024/06/07 19:13
如题所示,本程序是使用非AutoLayout写的UITableView自适应行高,之后笔者将会写一个基于AutoLayout的自适应行高的小demo。
PS:此小程序只适用于刚接触IOS的小朋友,只用做参考,毫无技术性,大神勿喷。
上代码:
//UITableViewCell#import <UIKit/UIKit.h>@interface commentaryCell : UITableViewCell@property (retain, nonatomic) UILabel *userID;@property (retain, nonatomic) UILabel *date;@property (retain, nonatomic) UILabel *commentary;-(void)setContent:(NSString *)userid_dic :(NSString *)date_dic :(NSString *)comment_dic;@end#import "commentaryCell.h"float width;float height;NSString *commentaryStr;@implementation commentaryCell@synthesize userID;@synthesize date;@synthesize commentary;- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.contentView.backgroundColor = [UIColor whiteColor]; [self createView]; } return self;}-(void)createView{ width = self.contentView.frame.size.width; height = self.contentView.frame.size.height; //用户ID userID = [[UILabel alloc] initWithFrame:CGRectMake(width*0.05, height*0.3, width*0.3, height*0.3)]; userID.font = [UIFont systemFontOfSize:14]; [userID setTextColor:[UIColor colorWithRed:85.0/255.0 green:85.0/255.0 blue:85.0/255.0 alpha:0.6]]; [self.contentView addSubview:userID]; //时间图标 //时间 date = [[UILabel alloc] initWithFrame:CGRectMake(width*0.4, height*0.3, width*0.5, height*0.3)]; date.font = [UIFont systemFontOfSize:14]; [date setTextColor:[UIColor colorWithRed:85.0/255.0 green:85.0/255.0 blue:85.0/255.0 alpha:0.6]]; [self.contentView addSubview:date]; //评论 commentary = [[UILabel alloc] init]; [commentary setNumberOfLines:0]; commentary.font = [UIFont systemFontOfSize:16]; [commentary setTextColor:[UIColor colorWithRed:85.0/255.0 green:85.0/255.0 blue:85.0/255.0 alpha:1]]; [self.contentView addSubview:commentary];}-(void)setContent:(NSString *)userid_dic :(NSString *)date_dic :(NSString *)comment_dic{ userID.text = userid_dic; date.text = date_dic; [commentary setNumberOfLines:0]; commentary.text = comment_dic; commentary.font = [UIFont systemFontOfSize:16]; CGSize commentSize = [self returnSize:commentary.text font:commentary.font]; [commentary setFrame:CGRectMake(width*0.05, 41, commentSize.width, commentSize.height)];}//返回Label的Size-(CGSize)returnSize:(NSString *)text font:(UIFont *)font{ float width = [UIScreen mainScreen].bounds.size.width; float height = [UIScreen mainScreen].bounds.size.height; CGSize _Size = CGSizeMake(width*0.9, height); CGSize Size = [text sizeWithFont:font constrainedToSize:_Size lineBreakMode:NSLineBreakByWordWrapping]; return Size;}
0 0
- IOS---UITableViewCell自适应行高(非AutoLayout)
- UITableViewCell AutoLayout 动态行高
- UITableViewCell高度自适应 autoLayout
- Autolayout uitableviewcell 自适应cell高度
- 使用Autolayout实现自适应UITableViewCell
- UITableViewCell使用AutoLayout自适应高度
- ios8 Autolayout实现uitableviewcell 高度自适应
- UITableViewCell高度自适应探索--AutoLayout结合Frame
- iOS - UITableViewCell自适应高度
- iOS自适应行高
- AutoLayout Label 自适应宽高
- [ios]UITableViewCell自适应高度 【转】
- iOS cell(UITableViewCell)自适应布局
- iOS 自适应label行高
- IOS 6.0+ Autolayout — UITableViewCell 高度调整
- iOS 6.0+ Autolayout — UITableViewCell 高度调整
- 结合AutoLayout实践iOS8上UITableViewCell高度的自适应
- IOS UITableViewCell单个Cell自适应显示多行
- 数据类型 转换
- Mac系统下Apache+PHP+MySql搭建
- C/C++_ const int * 与 int *const的区别
- 简单table和form示例
- JSP的范围(scope)之pageContext、request、session和application
- IOS---UITableViewCell自适应行高(非AutoLayout)
- 程序员学英语
- 【前端进阶01】利用@font-face定义并使用自己喜欢的字体
- Android实战技术: 用Dimension解决多屏幕适配的问题
- 微信公众平台开发
- 大型网站架构演变和知识体系
- C++ Boost智能指针
- 【数据库系列(二)】锁机制
- struts2.0的标签库 详解