2012-12-29 76 views
7

我创建了我的类MyStyledStringElement和子类StyledStringElement和IElementSizing,试图控制样式化元素的宽度。不幸的是,下面的代码只调整getheight()中单元格的高度。有没有可以使用的getWidth()方法或类似的东西来调整样式化元素的宽度,使其看起来与UIButton相同?一如既往地感谢。monotouch.dialog styledstringelement调整单元格宽度

public override UITableViewCell GetCell (UITableView tv) 
    { 
     var cell = base.GetCell (tv); 
     cell.AutosizesSubviews = false; 
     //tv.TranslatesAutoresizingMaskIntoConstraints = false; 
     cell.ClipsToBounds = false; 
     cell.Frame.Width = 30; 
     cell.Bounds.Width = 30; 
     cell.Frame.Size = new System.Drawing.SizeF (30, 30); 

     return cell; 
    } 


    #region IElementSizing implementation 
    public float GetHeight (UITableView tableView, NSIndexPath indexPath) 
    { 
     //throw new NotImplementedException(); 



     tableView.Frame.Width = 10; 
     //tableView.Bounds.Width = 10; 

     tableView.Frame.Height = 10; 

     Console.WriteLine (tableView.ToString()); 

     return 10; 
    } 
    #endregion 

回答

1

上次我看了这个,宽度由UITableView控制。你最好的选择是添加一个UIButton作为UITableViewCell的一个子元素,并返回你需要包含这个按钮的高度。