调整xamarin中的细胞大小

时间:2014-07-28 14:33:27

标签: ios uitableview xamarin

A cell in a TableView of Xamarin

我有一个用Xamarin构建的表格视图,其中填充了一些地址,但我无法弄清楚如何调整单元格的大小以便所有信息都适合。

我的TableViewCell类:

using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.CodeDom.Compiler;
using System.Drawing;

namespace Vipar
{
    public class CustomVegeeeCell : UITableViewCell  {
        UILabel Title, Addr, CityState;
        //UIImageView imageView;
        public CustomVegeeeCell (NSString cellId) : base (UITableViewCellStyle.Default, cellId)
        {
            SelectionStyle = UITableViewCellSelectionStyle.Gray;
            ContentView.BackgroundColor = UIColor.Clear;//(84, 84, 85);

            //imageView = new UIImageView();
            Title = new UILabel () {
                Font = UIFont.FromName("Arial-BoldMT", 16f),
                TextColor = UIColor.Black,

                BackgroundColor = UIColor.Clear
            };
            Addr = new UILabel () {
                Font = UIFont.FromName("ArialMT", 12f),
                TextColor = UIColor.Black,
                //TextAlignment = UITextAlignment.Center,
                BackgroundColor = UIColor.Clear
            };
            CityState = new UILabel () {
                Font = UIFont.FromName("ArialMT", 12f),
                TextColor = UIColor.Black,
                //TextAlignment = UITextAlignment.Center,
                BackgroundColor = UIColor.Clear
            };
            ContentView.Add (Title);
            ContentView.Add (Addr);
            ContentView.Add (CityState);
        }
        public void UpdateCell (string caption, string subtitle, string subtitle1)//, UIImage image)
        {
            //imageView.Image = image;
            Title.Text = caption;
            Addr.Text = subtitle;
            CityState.Text = subtitle1;
        }
        public override void LayoutSubviews ()
        {
            base.LayoutSubviews ();
            //imageView.Frame = new RectangleF(ContentView.Bounds.Width - 63, 5, 33, 33);
            Title.Frame = new RectangleF(5, 4, ContentView.Bounds.Width - 63, 25);
            Addr.Frame = new RectangleF(5, 18, ContentView.Bounds.Width - 63, 25);
            CityState.Frame = new RectangleF(5, 30, ContentView.Bounds.Width - 63, 25);
        }
    }
}

1 个答案:

答案 0 :(得分:2)

在UITableViewSource中,您需要覆盖GetHeightForRow:

public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)