iOS tip:让你的footTableView的UILabel居中

如果你需要编写一个软件,同时支持portrait&landscape,你会遇到一个问题:当屏幕旋转后,如果才能确保一些可视化的things依然居中呢。下面是一个简单的例子,无论设备是否旋转,UITableView的footer中的UILabel保持居中的方法。

 1     //create the uiview container
 2     UIView *tfooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tableView.frame.size.width, 45)];
 3     tfooterView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
 4     //create the uilabel for the text
 5     UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(_tableView.frame.size.width/2-120, 0, 240, 35)];
 6     label3.backgroundColor = [UIColor clearColor];
 7     label3.font = [UIFont systemFontOfSize:12];
 8     label3.numberOfLines = 2;
 9     label3.lineBreakMode = UILineBreakModeWordWrap;
10     label3.textAlignment = UITextAlignmentCenter;
11     label3.text = @"Some text you want centered in your tableFooterView.";
12     label3.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
13     //add the label to the view
14     [tfooterView addSubview:label3];
15     //add the view to the uitableview footer
16     _tableView.tableFooterView = tfooterView;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值