我在iPad屏幕上使用MonoTouch.Dialog。
我已经创建了一个全屏背景,并在其上绘制了一个MonoTouch.Dialog表。
我希望更改MonoTouch.Dialog表格(或所有单元格)的宽度,同时保留全屏背景不变。我该怎么做呢?
发布于 2013-08-13 22:10:11
您不能直接这样做,因为DialogViewController类似于UITableViewController和UITableView,它们有一些特征来填充其包含的空格。有一个巧妙的技巧可以解决这个问题,你需要为你想要的宽度创建一个“容器”UIView,并将它作为一个子视图添加到UIViewController中。现在创建您的DialogViewController,并将其视图添加为该容器的子视图。对话框将扩展到容器的大小,而不是父视图的大小。
你应该会得到类似这样的结果:
public class MyController : UIViewController
{
UIView container;
DialogViewController dvc;
public override void ViewDidLoad()
{
base.ViewDidLoad();
container = new UIView();
dvc = new DialogViewController(UITableViewStyle.Grouped, null, true);
dvc.Root = new Root("Title") {
new Section() {
new StringElement("Hello")
}
};
View.AddSubview(container);
}
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
// Whatever width you want
float newWidth = View.Bounds.Width / 2;
container.Frame = new RectangleF(0, 0, newWidth, View.Bounds.Height);
// This is a workaround so that the TableView fills the container view
// after it is sized.
container.AddSubView(dvc.View);
}
}https://stackoverflow.com/questions/9940216
复制相似问题