0
我想在uitableviewcell中顯示地址信息,並且使用帶自動佈局的自定義單元格。我認爲,不是爲地址字段設置單獨的標籤,而是使用單個標籤並將地址字段拼接在一起,並使用換行符「\ n」,以便每個地址字段出現在標籤的新行中,然後我設置標籤的行數爲零,以便它自動擴展當單元格包含帶有新行字符的uilabel時,heightForRowAtIndexPath不正確
這部分工作正常,什麼不工作是當我嘗試計算heightForRowAtIndexPath,它低報什麼標籤大小將是如此地址越來越截斷
例如這裏是一些代碼提取:它似乎像boundingRectWithSize沒有考慮到換行符或許嗎?無論如何,我試圖不使用單個標籤,而是有單獨的領域,這將是更多的工作,但我認爲它不會運行int o這些問題。
NSString *description= [self getAddressDescription:_delegate.shoppingCart.shippingAddress]; // formats address fields into single string with newline characters
NSAttributedString *attributedText =
[[NSAttributedString alloc]
initWithString:description
attributes:@
{
NSFontAttributeName: [ViewHelper getDescriptionFont]
}];
CGRect rect = [attributedText boundingRectWithSize:(CGSize){200, CGFLOAT_MAX}
options:NSStringDrawingUsesLineFragmentOrigin
context:nil];
CGSize descriptionSize = rect.size;
return kParentChildDefaultSpace + + descriptionSize.height + kParentChildDefaultSpace;