UITableView UITableViewCellStyle.Value1 TextLabel与DetailTextLabel重叠

时间:2015-12-16 17:40:59

标签: ios uitableview xamarin xamarin.ios

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

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

Image showing text overlapping

2 个答案:

答案 0 :(得分: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;
            }
        }
}

答案 1 :(得分: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
    }
}