private void UpdateExpendSize(string desc) { if (string.IsNullOrEmpty(desc)) { return; } if (desc.Length < columnMax) { mTransform.sizeDelta = new Vector2(defaultSize.x, defaultSize.y); return; } int chinaNum = 0; int letterNum = 0; int otherNum = 0; for (int i = 0; i < desc.Length; i += 1) { if (LogicUtil.IsChinaChar(desc.Substring(i, 1))) { chinaNum += 1; } else if (LogicUtil.IsLetterOrNumber(desc.Substring(i, 1))) { letterNum += 1; } else { otherNum += 1; } } int count = chinaNum + letterNum / 2 + otherNum / 2; int maxLine = Mathf.CeilToInt(count / (float)columnMax) - 1; if (maxLine < 0) { maxLine = 1; } float offY = defaultSize.y + maxLine * charLineHeight; mTransform.sizeDelta = new Vector2(defaultSize.x, offY); }
private void UpdateExpendSize(string desc, bool tag, int images) { int chinaNum = 0; int letterNum = 0; int otherNum = 0; for (int i = 0; i < desc.Length; i += 1) { if (LogicUtil.IsChinaChar(desc.Substring(i, 1))) { chinaNum += 1; } else if (LogicUtil.IsLetterOrNumber(desc.Substring(i, 1))) { letterNum += 1; } else { otherNum += 1; } } int count = chinaNum + letterNum / 2 + otherNum / 2; int maxLine = Mathf.CeilToInt(count / (float)columnMax) - 1; if (maxLine < 1) { maxLine = 1; } descLabel.rectTransform.sizeDelta = new Vector2(descLabel.rectTransform.sizeDelta.x, maxLine * charLineHeight); imageContent.sizeDelta = new Vector2(imageContent.sizeDelta.x, images * imageHeight); float offY = defaultHeight + maxLine * charLineHeight + images * imageHeight; if (tag) { offY += tagHeight; } mTransform.DOSizeDelta(new Vector2(mTransform.sizeDelta.x, offY), 0.2f).OnUpdate(() => { ViewItem.ParentListView.OnItemSizeChanged(viewItem.ItemIndex); }); }