2012-12-29 75 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的一個子元素,並返回你需要包含這個按鈕的高度。