我在單元格中有一個UITableview是很多標籤。我想根據cellForRowAt方法中的設備設置字體大小,但字體大小沒有設置第一次。當我滾動然後將實現代碼如下回屏幕,然後字體大小set.How解決這一issue.Below代碼使用cellForRowAtUITableview單元格標籤字體大小未設置第一次
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)
}
也許你可以顯示你的一些代碼? – koropok
我添加了代碼。 –
是這個確切的代碼你在你的代碼庫中使用什麼?您不會在每個案例陳述後使用** break; **這可能是您可以重新檢查的原因 – gEeKyMiNd