我的UITableViewCell在iPad上出现问题。这个问题在iOS 7和现在之间出现了,但我不确定它何时开始。在iPod或iPhone上,我的手机看起来很好(纵向或横向),但在iPad上,显示配件非常宽。您可以在下图中看到一个示例。 tablecell有一个绿色边框,contentview有一个棕色边框。内容视图比应该小得多。没有公开附件的台式电池看起来很好。
我正在使用Xamarin,我在代码中完全创建了这个UI。这是代码(我省略了在单元格内部放置ContentView的代码,因为它不相关:
protected void Draw()
{
Accessory = UITableViewCellAccessory.DisclosureIndicator;
Layer.BorderColor = UIColor.Green.CGColor;
Layer.BorderWidth = 1f;
Frame = new CGRect(0, 0, 320, 42);
ContentMode = UIViewContentMode.ScaleToFill;
AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
ContentView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
ContentView.MultipleTouchEnabled = true;
ContentView.ContentMode = UIViewContentMode.Center;
ContentView.ClipsToBounds = true;
ContentView.Layer.BorderColor = UIColor.Brown.CGColor;
ContentView.Layer.BorderWidth = 1f;
}
我尝试通过覆盖单元格的LayoutSubviews方法来更改ContentView的大小。但是,ContentView现在和表格一样宽,但是公开附件没有改变,现在位于ContentView之下。
public override void LayoutSubviews()
{
base.LayoutSubviews();
//ContentView.Frame = new CGRect(0, 0, Frame.Size.Width, ContentView.Frame.Size.Height);
}
同样,这在iPhone或iPod上根本不是问题。我不明白我应该做些什么来让iPad正常工作。
感谢。 Zach Green
编辑 - 2015年10月21日11:00 目前,我已经做了一个非常黑客的改变,正在为我解决这个问题,但我知道未来的iOS更新可能会破坏这一点,所以我更倾向于采用iOS批准的方式来实现这一目标。
public override void LayoutSubviews()
{
base.LayoutSubviews();
//!! - Hack for ipad layout issue with disclosure indicator
if (Accessory == UITableViewCellAccessory.DisclosureIndicator && UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
ContentView.Frame = new CGRect(0, 0, Frame.Size.Width - 32, ContentView.Frame.Size.Height);
foreach (var view in Subviews.OfType<UIButton>())
{
view.Frame = new CGRect(Frame.Size.Width - 24, view.Frame.Y, 8, view.Frame.Height);
}
}
}
答案 0 :(得分:41)
这是因为Apples在iOS9中具有新的可读内容边距,旨在使内容在更广泛的视图中更具可读性(iPad Pro)。
您可以通过设置
关闭此功能@Override
protected void onCreate(Bundle savedInstanceState) {
//...
try {
TextBox textBox = JsonToTextBox();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
在viewDidLoad
中答案 1 :(得分:4)
试试这段代码:
protected void Draw()
{
Accessory = UITableViewCellAccessory.DisclosureIndicator;
Layer.BorderColor = UIColor.Green.CGColor;
Layer.BorderWidth = 1f;
Frame = new CGRect(0, 0, [UIApplication sharedApplication].keywindow.frame.size.width, 42);
ContentMode = UIViewContentMode.ScaleToFill;
AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
ContentView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
ContentView.MultipleTouchEnabled = true;
ContentView.ContentMode = UIViewContentMode.Center;
ContentView.ClipsToBounds = true;
ContentView.Layer.BorderColor = UIColor.Brown.CGColor;
ContentView.Layer.BorderWidth = 1f;
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
//!! - Hack for ipad layout issue with disclosure indicator
if (Accessory == UITableViewCellAccessory.DisclosureIndicator && UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
{
ContentView.Frame = new CGRect(0, 0, [UIApplication sharedApplication].keywindow.frame.size.width - 32, ContentView.Frame.Size.Height);
foreach (var view in Subviews.OfType<UIButton>())
{
view.Frame = new CGRect([UIApplication sharedApplication].keywindow.frame.size.width - 24, view.Frame.Y, 8, view.Frame.Height);
}
}
}
答案 2 :(得分:1)
使用与[UIApplication sharedApplication].keyWindow.frame.size.width
相同的宽度,而不是硬编码值。