UITableView UITableViewCellStyle.Value1 TextLabel与DetailTextLabel重叠

问题描述 投票:2回答:2

我正在使用Xamarin iOS,在iOS 9.2设备上,UITableViewCellStyle.Value1的单元格样式的UITableView单元格具有与DetailTextLabel重叠的TextLabel。

在iOS 8上不会发生这种情况。任何人都知道我可以做什么来修复它而不用滚动自己的单元格?我只想将TextLabel省略,而不是重叠DetailTextLabel。

Image showing text overlapping

ios uitableview xamarin xamarin.ios
2个回答
0
投票

我找不到修复方法。一个空白项目只用一个简单的TableView重现它,所以我推出了自己的自定义单元格。

public class CustomTableViewCell : UITableViewCell
{
        UILabel headingLabel, subheadingLabel;

        public MTableViewCell (NSString cellId) : base (UITableViewCellStyle.Default, cellId)
        {
            SelectionStyle = UITableViewCellSelectionStyle.Default;
            headingLabel = new UILabel ();
            subheadingLabel = new UILabel () {
                TextColor = UIColor.Gray,
                TextAlignment = UITextAlignment.Center
            };
            ContentView.AddSubviews (new UIView[] { headingLabel, subheadingLabel });
        }

        public override void LayoutSubviews ()
        {
            base.LayoutSubviews ();
            headingLabel.Frame = new CGRect (15, 0, ContentView.Bounds.Width - 130, ContentView.Bounds.Height);
            subheadingLabel.Frame = new CGRect (ContentView.Bounds.Width - 110, 0, 95, ContentView.Bounds.Height);
        }

        public override UILabel TextLabel {
            get {
                return headingLabel;
            }
        }

        public override UILabel DetailTextLabel {
            get {
                return subheadingLabel;
            }
        }
}

0
投票

Pasudocode决定是否要将value1或子类型的单元格出列

public static func isVerticalLayout(primary: String, secondary: NSAttributedString,
                                    liveHostView: UIView) -> Bool
{
    let csWidth = liveHostView.bounds.width

    let headingLabel = UILabel()
    let subheadingLabel = UILabel()
    headingLabel.text = primary
    headingLabel.numberOfLines = 0
    headingLabel.lineBreakMode = .byWordWrapping
    subheadingLabel.attributedText = secondary
    subheadingLabel.textAlignment = .right
    subheadingLabel.numberOfLines = 1
    subheadingLabel.lineBreakMode = .byWordWrapping

    let clipw =  csWidth - P97GEL.Constants.leftTextMargin - P97GEL.Constants.rightTextMargin
    let bounds = CGRect(x: 0, y: 0, width: clipw, height: CGFloat.greatestFiniteMagnitude)
    let psRect = headingLabel.textRect(forBounds: bounds, limitedToNumberOfLines: 1)
    let ps = psRect.size
    let ssRect = subheadingLabel.textRect(forBounds: bounds, limitedToNumberOfLines: 1)
    let ss = ssRect.size

    headingLabel.frame.origin = CGPoint(x: P97GEL.Constants.leftTextMargin, y: P97GEL.Constants.verticalMargin)
    headingLabel.frame.size = ps
    subheadingLabel.frame.size = ss

    if csWidth >= ps.width + ss.width + (3 * P97GEL.Constants.horizontalMargin) {
        return false
    } else {
        return true
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.