#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
#import "AppDelegate.h"
#import "MovieHomeController.h"
@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor]; UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:[[MovieHomeController alloc] init]]; self.window.rootViewController = navi; [self.window makeKeyAndVisible];
return YES;
} @end
#import <UIKit/UIKit.h>

@interface MovieHomeController : UIViewController

@end
#import "MovieHomeController.h"
#import "CinemaInfomationCell.h" //#import "SGFocusImageFrame.h" #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define IS_IOS7 (IOS_VERSION >= 7.0 ? YES : NO) #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define scale SCREEN_WIDTH/320.0
#define advertScrollView_height 100*scale @interface MovieHomeController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
{
// UIScrollView *_advertScrollView;
// NSMutableArray *advertImages;
UITableView *_tableView; NSMutableArray *datas;
}
//@property(nonatomic, strong) SGFocusImageFrame *bannerView;//banner栏
@end @implementation MovieHomeController - (void)viewDidLoad {
[super viewDidLoad];
self.title = @"电影"; datas = [[NSMutableArray alloc] init];
NSArray *arr = @[@"哈艺时尚影城(白云YH城店)",@"20%",@"",@"广州市白云区广州大道北28号梅花园商业中心302",@"6.2km",@"",@"座",@"主题",@"满"];//立开
[datas addObject:arr]; self.view.backgroundColor = [UIColor lightGrayColor];
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain];
_tableView.dataSource = self;
_tableView.delegate = self;
[self.view addSubview:_tableView]; } #pragma mark -- tableView 的数据源配置 --
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return datas.count;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"cell";
CinemaInfomationCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[CinemaInfomationCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
NSArray *info = datas[indexPath.row];
cell.cinemaName.text = info[];
cell.rebateAccount.text = [NSString stringWithFormat:@"返%@",info[]];
cell.score.text = [NSString stringWithFormat:@"%@分",info[]];
cell.address.text = info[];
cell.distance.text = info[];
cell.price.text = [NSString stringWithFormat:@"¥ %@",info[]];
cell.style.text = info[];
cell.theme.text = info[];
cell.seat.text = info[];
// NSLog(@"******%@",info[0]);
return cell;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
#import <UIKit/UIKit.h>

@interface CinemaInfomationCell : UITableViewCell

@property (nonatomic, strong) UILabel *cinemaName;//电影院名称
@property (nonatomic, strong) UILabel *rebateAccount;//返利金
@property (nonatomic, strong) UILabel *score; //等级评分
@property (nonatomic, strong) UILabel *address;//地址
@property (nonatomic, strong) UILabel *price;//价格
@property (nonatomic, strong) UILabel *distance;//距离
@property (nonatomic, strong) UILabel *seat;//座
@property (nonatomic, strong) UILabel *theme;//主题
@property (nonatomic, strong) UILabel *style;//满或其它的 @end
#import "CinemaInfomationCell.h"

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define top_height 5
#define cinemaName_height 30
#define rebateAccount_height 17
#define address_height 30
#define price_height 30
@interface CinemaInfomationCell ()
{
UIView *line;//底部的细线
UILabel *label;//起字
UIView *verticalLine1;//竖线
UIView *verticalLine2;//竖线
}
@end @implementation CinemaInfomationCell - (void)awakeFromNib {
// Initialization code
} - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.cinemaName = [[UILabel alloc] init];
[self addSubview:self.cinemaName]; self.rebateAccount = [[UILabel alloc] init]; self.rebateAccount.backgroundColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:];
self.rebateAccount.font = [UIFont systemFontOfSize:];
self.rebateAccount.textColor = [UIColor whiteColor];
self.rebateAccount.textAlignment = NSTextAlignmentCenter;
self.rebateAccount.layer.cornerRadius = ;
self.rebateAccount.clipsToBounds = YES;
[self addSubview:self.rebateAccount]; self.score = [[UILabel alloc] init];
self.score.layer.borderColor = [[UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:] CGColor];
self.score.layer.borderWidth = 1.5;
self.score.font = [UIFont systemFontOfSize:];
self.score.textColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:];
self.score.layer.cornerRadius = ;
self.score.clipsToBounds = YES;
self.score.textAlignment = NSTextAlignmentCenter;
[self addSubview:self.score]; self.address = [[UILabel alloc] init];
self.address.textColor = [UIColor grayColor];
self.address.font = [UIFont systemFontOfSize:];
self.address.backgroundColor = [UIColor clearColor];
[self addSubview:self.address]; self.distance = [[UILabel alloc] init];
self.distance.textColor = [UIColor grayColor];
self.distance.font = [UIFont systemFontOfSize:];
self.distance.backgroundColor = [UIColor clearColor];
self.distance.textAlignment = NSTextAlignmentCenter;
[self addSubview:self.distance]; self.price = [[UILabel alloc] init];
self.price.backgroundColor = [UIColor clearColor];
self.price.font = [UIFont systemFontOfSize:];
self.price.textColor = [UIColor colorWithRed:/255.0 green: blue:/255.0 alpha:1.0];
self.price.textAlignment = NSTextAlignmentRight;
[self addSubview:self.price]; //起字
label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithRed:/255.0 green: blue:/255.0 alpha:1.0];
label.text = @" 起";
label.textAlignment = NSTextAlignmentLeft;
label.font = [UIFont systemFontOfSize:];
[self addSubview:label]; self.style = [[UILabel alloc] init];
self.style.backgroundColor = [UIColor clearColor];
self.style.font = [UIFont systemFontOfSize:];
self.style.textColor = [UIColor grayColor];
[self addSubview:self.style]; verticalLine1 = [[UIView alloc] init];
verticalLine1.backgroundColor = [UIColor grayColor];
[self addSubview:verticalLine1]; self.theme = [[UILabel alloc] init];
self.theme.backgroundColor = [UIColor clearColor];
self.theme.font = [UIFont systemFontOfSize:];
self.theme.textColor = [UIColor grayColor];
self.theme.textAlignment = NSTextAlignmentCenter;
[self addSubview:self.theme]; verticalLine2 = [[UIView alloc] init];
verticalLine2.backgroundColor = [UIColor grayColor];
[self addSubview:verticalLine2]; self.seat = [[UILabel alloc] init];
self.seat.backgroundColor = [UIColor clearColor];
self.seat.font = [UIFont systemFontOfSize:];
self.seat.textColor = [UIColor grayColor];
self.seat.textAlignment = NSTextAlignmentRight;
[self addSubview:self.seat]; //底部的细线
line = [[UIView alloc] init];
line.backgroundColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:];
[self addSubview:line]; }
return self;
} - (void)layoutSubviews{
[super layoutSubviews];
//计算文字的宽度
self.cinemaName.numberOfLines = ;
UIFont *font = [UIFont fontWithName:@"Arial" size:];
self.cinemaName.font = font;
CGSize constraint = CGSizeMake(self.frame.size.width - , );
CGSize size = [self.cinemaName.text sizeWithFont:font constrainedToSize:constraint lineBreakMode:NSLineBreakByWordWrapping];
NSLog(@"===%@==%f",self.cinemaName.text,size.width);
self.cinemaName.frame = CGRectMake(, top_height, size.width+,cinemaName_height); self.rebateAccount.frame = CGRectMake(CGRectGetMaxX(self.cinemaName.frame), CGRectGetMidY(self.cinemaName.frame) - rebateAccount_height/2.0, , rebateAccount_height); self.score.frame = CGRectMake(CGRectGetMaxX(self.rebateAccount.frame)+, self.rebateAccount.frame.origin.y, , rebateAccount_height); self.address.frame = CGRectMake(, CGRectGetMaxY(self.cinemaName.frame), SCREEN_WIDTH - , address_height); self.distance.frame = CGRectMake(SCREEN_WIDTH - , self.address.frame.origin.y, , address_height); self.price.frame = CGRectMake(, CGRectGetMaxY(self.address.frame), , price_height); label.frame = CGRectMake(CGRectGetMaxX(self.price.frame), self.price.frame.origin.y+, , price_height); self.style.frame = CGRectMake(SCREEN_WIDTH - , CGRectGetMaxY(self.address.frame), , price_height); verticalLine1.frame = CGRectMake(CGRectGetMinX( self.style.frame) - , CGRectGetMidY(self.style.frame)-/2.0, , ); self.theme.frame = CGRectMake(CGRectGetMinX(verticalLine1.frame)--, CGRectGetMinY(self.style.frame), , price_height); verticalLine2.frame = CGRectMake(CGRectGetMinX(self.theme.frame)-, CGRectGetMidY(self.style.frame)-/2.0, , ); self.seat.frame = CGRectMake(CGRectGetMinX(verticalLine2.frame)--, CGRectGetMinY(self.style.frame), , price_height); line.frame = CGRectMake(,self.frame.size.height - ,SCREEN_WIDTH,);
} - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
// [super setSelected:selected animated:animated];
// Configure the view for the selected state
} - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
} @end

iOS 重写UITableViewCell之动态获取label文字的宽度进行布局的更多相关文章

  1. 根据文字动态计算Label高度或宽度

    //根据已知的label宽度计算文字高度 CGRect rect = [reson boundingRectWithSize:CGSizeMake(label_W, 0) options:NSStri ...

  2. swift 动态获取label宽度或高度

    func getLabHeigh(labelStr:String,font:UIFont,width:CGFloat) -> CGFloat { let statusLabelText: NSS ...

  3. iOS根据文字字数动态确定Label宽高

    我们有时候在写项目的时候,会碰到,意见反馈,还有其他地方,讲座活动细则等需要大篇展示的文本, 因为每次服务器返回的内容大小不一,所以需要动态的调整label的宽高: 在ios 6 的时候可以: -(v ...

  4. iOS 根据文字字数动态确定Label宽高

    iOS7中用以下方法 - (CGSize)sizeWithAttributes:(NSDictionary *)attrs; 替代过时的iOS6中的- (CGSize)sizeWithFont:(UI ...

  5. 李洪强iOS开发之动态获取UILabel的bounds

    李洪强iOS开发之动态获取UILabel的bounds 在使用UILabel存放字符串时,经常需要获取label的长宽数据,本文列出了部分常用的计算方法. 1.获取宽度,获取字符串不折行单行显示时所需 ...

  6. iOS_根据文字字数动态确定Label宽高

    iOS7中用以下方法 CGSize 替代过时的iOS6中的- (CGSize)sizeWithFont:(UIFont *)font 方法 // iOS7_API_根据文字 字数动态确定Label宽高 ...

  7. iOS开发遇到的错误 -- Label显示多行文字导致宽度和高度的问题

    Label的宽度问题 注意:UILabel下面需要设置preferredMaxLayoutWidth ,设置了autolayout和numberofline的UIlabel才显示多行 label宽度的 ...

  8. iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局

    iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局 一.项目文件结构和plist文件 二.实现效果 三.代码示例 1.没有使用配套的类,而是直接使用xib文 ...

  9. iPhone:动态获取UILabel的高度和宽度

    转自:http://www.cnblogs.com/spiritstudio/archive/2011/11/17/2252074.html 在使用UILabel存放字符串时,经常需要获取label的 ...

随机推荐

  1. EasyUI datagrid 在ie8和360兼容模式兼容性问题

    问题:easyui中的datagrid在ie8和360兼容模式下显示不出来. 答案:不是easyui的问题.是引入的jquery版本问题.jquery-1.5.1抛异常,这个版本是mvc3自带的jqu ...

  2. 动态input file多文件上传到后台没反应的解决方法!!!

    其实我也不太清除具体是什么原因,但是后面就可以了!!! 我用的是springMVC 自带的文件上传 1.首先肯定是要有springMVC上传文件的相关配置! 2.前端 这是动态input file上传 ...

  3. DX11.2 Tiled Resource Pool

    Nvidia white paper : https://developer.nvidia.com/content/taking-advantage-directx112-tiled-resource ...

  4. 为什么数值类型byte取值范围是(-128~127)?

    在解决这个问题之前,我们先了解几个概念? 一.原码, 反码, 补码的概念 正数的反码和补码都与原码一样: 负数的反码.补码与原码不同,负数的反码:原码中除去符号位,其他的数值位取反,0变1,1变0.负 ...

  5. Distinctive Image Features from Scale-Invariant

    http://nichol.as/papers/Lowe/Distinctive Image Features from Scale-Invariant.pdf Abstract This paper ...

  6. java动态联编

    JAVA中联编有两种,一种是动态联编,一种是静态联编. 动态联编:也叫多态联编或者是迟后联编,因为到底要调用哪一个函数,在编译时不能确定,而要推迟到运行中确定.也就是说,要等到程序运行时,确定了指针所 ...

  7. 【转】HideInInspector 与SerializeField

    http://blog.csdn.net/luyuncsd123/article/details/21563697 [HideInInspector]表示将原本显示在面板上的序列化值隐藏起来. [Se ...

  8. 基于ace后台管理系统模板--CMS(Thinkphp框架)的筹划

    临近春节,准备自己做一个关于宠物的cms网站,特写下此博客提醒自己,尽量争取在过年前做好.废号少说,先梳理下接下来准备使用的工具.. 由于最近在学习thinkphp,所以打算用这个框架来作为主体,可能 ...

  9. android 2.2 videoView 诡异bug

    最近遇到一个问题,在2.2系统上,公司项目中使用VideoView,第一次播放正常,第二次播放黑屏. 由于公司项目使用lua + android 原生,所以试了下原生的android 的VideoVi ...

  10. 变态的HelloWorld

    public static void main(String[] args) { int i, n[] = { (((1 << 1) << (1 << 1) < ...