【发布时间】:2017-11-03 09:23:23
【问题描述】:
我有一个UITableview 在一个单元格中有很多标签。我想在cellForRowAt方法中根据设备设置字体大小,但第一次没有设置字体大小。当我滚动 tableview 然后将返回屏幕然后设置字体大小。如何解决这个问题。下面的代码在cellForRowAt中使用
cell.lbl_desc.adjustsFontSizeToFitWidth=true
cell.lbl_price.adjustsFontSizeToFitWidth=true
cell.lbl_qty.adjustsFontSizeToFitWidth=true
let bounds = UIScreen.main.bounds
let height = bounds.size.height
switch height
{
case 568.0:
print("iPhone 5")
cell.lbl_desc.font = cell.lbl_desc.font.withSize(13)
cell.lbl_price.font = cell.lbl_price.font.withSize(13)
cell.lbl_qty.font = cell.lbl_qty.font.withSize(13)
case 667.0:
print("iPhone 6")
cell.lbl_desc.font = cell.lbl_desc.font.withSize(15)
cell.lbl_price.font = cell.lbl_price.font.withSize(15)
cell.lbl_qty.font = cell.lbl_qty.font.withSize(15)
case 736.0:
print("iPhone 6+")
cell.lbl_desc.font = cell.lbl_desc.font.withSize(16)
cell.lbl_price.font = cell.lbl_price.font.withSize(16)
cell.lbl_qty.font = cell.lbl_qty.font.withSize(16)
default:
print("iPad")
cell.lbl_desc.font = cell.lbl_desc.font.withSize(18)
cell.lbl_price.font = cell.lbl_price.font.withSize(18)
cell.lbl_qty.font = cell.lbl_qty.font.withSize(18)
}
【问题讨论】:
-
也许你可以展示一些你的代码?
-
我添加了代码。
-
这是您在代码库中使用的确切代码吗?您不要在每个 case 语句之后使用 break; ...这可能是您可以重新检查的原因
-
是的,这是确切的代码。
-
switch ([error code]) { case kPFErrorObjectNotFound: // Handle error. break; case kPFErrorConnectionFailed: // Handle error. break; default: // Handle error. }
标签: ios swift uitableview uifont