#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. 如何用Apache POI操作Excel文件-----如何用Apache POI 画一个离散图

    有的时候,我们需要Excel中的数据,通过一个图画,可视化的表现出来. 那么这个时候,应该如何做呢?现在就借花献佛,以Apache POI自己提供的一个例子为例,给大家演示一下POI的API 如何画图 ...

  2. FZU 2171 线段树 区间更新求和

    很模板的题 在建树的时候输入 求和后更新 #include<stdio.h> #include<string.h> #include<algorithm> #inc ...

  3. HTML: 文檔流是什麼?

    [作者好人]:http://www.nowamagic.net/librarys/veda/detail/1190 文档流 将窗体自上而下分成一行行, 并在每行中按从左至右的顺序排放元素,即为文档流. ...

  4. Android轻量缓存框架--ASimpleCache

    [转] 大神真面目 稀土掘金,这是一个针对技术开发者的一个应用,你可以在掘金上获取最新最优质的技术干货,不仅仅是Android知识.前端.后端以至于产品和设计都有涉猎,想成为全栈工程师的朋友不要错过! ...

  5. 【转】下载量最高的 100 个 Laravel 扩展包推荐

    说明 Laravel 另一个令人喜欢的地方,是拥有活跃的开发者社区,而活跃的开发者社区带来的,是繁华的扩展包生态. 本文对 Packagist 上打了 Laravel 标签 的扩展包进行整理,截止到现 ...

  6. log4j常用配置以及日志文件保存位置

    log4j.rootLogger=INFO,CONSOLE log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender ...

  7. document.execCommand(”BackgroundImageCache”, false, true)

    很多时候我们要给一些按钮或是img设置背景,而为了达到数据与表现样式分离的效果,通常背景样式都是在CSS里设定的,但是这个行为在IE会有一 个Bug,那就是因为 IE默认情况下不缓存背景图片,所以当鼠 ...

  8. 转 创建 JavaScript XML 文档注释

    http://www.cnblogs.com/chenxizhang/archive/2009/07/12/1522058.html 如何:创建 JavaScript XML 文档注释 Visual ...

  9. 【转】Servlet与web.xml的配置

    Web.xml常用元素<web-app><display-name></display-name>定义了WEB应用的名字<description>< ...

  10. javaScript没有块级作用域

    1.如下,变量i,j,k 的作用域是相同的. function test(obj){ var i= 0; if(typeof obj == "object"){ var j = 0 ...