【发布时间】:2015-05-02 11:17:30
【问题描述】:
我想创建一个UIView,它将根据 iPhone 屏幕尺寸调整其宽度,并且它应该保持在视图的底部。
我用故事板创建了新项目并添加了以下代码。
这是我的代码
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:true];
UIView *box = [[UIView alloc]initWithFrame:CGRectMake(0, 448, 320, 120)];
[box setBackgroundColor:[UIColor redColor]];
[box setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[box setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[box setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
[box setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
[box setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
[self.view addSubview:box];
}
自动布局已关闭。
如果我通过从界面生成器应用自动调整大小来做同样的事情,那么它工作得很好。
我不明白为什么它不起作用。
【问题讨论】:
标签: ios objective-c uiview storyboard autoresizingmask