【问题标题】:iOS UIViewController layout issueiOS UIViewController 布局问题
【发布时间】:2014-12-09 12:04:58
【问题描述】:

我已经开始在没有界面生成器的情况下开发 iOS。

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ViewController *viewController = [[ViewController alloc] init];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.rootViewController = viewController;

    [self.window makeKeyAndVisible];

    return YES;
}

ViewController.m

- (void)loadView
{
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
    UIView *contentView = [[UIView alloc] initWithFrame:applicationFrame];
    contentView.backgroundColor = [UIColor whiteColor];
    self.view = contentView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 280, 20)];
    [label setText:@"ViewController"];
    [label setTextAlignment:NSTextAlignmentCenter];
    [label setBackgroundColor:[UIColor redColor]];
    [self.view addSubview:label];
}

我不知道为什么,但是当我加载应用程序时,顶部蚂蚁按钮和视图之间有空间。有人知道为什么吗?

【问题讨论】:

  • 项目需要添加Default-568h@2x.png背景图片
  • 我刚刚在 6 plus 模拟器中运行了您的代码。我没有看到黑色区域
  • @Gonji Dev,你的答案是正确的!如果你发布它,我会标记它为正确的!

标签: ios objective-c iphone uiviewcontroller


【解决方案1】:

您需要将 Default-568h@2x.png 背景图片添加到项目中。

【讨论】:

    【解决方案2】:

    如果您的部署目标是 iOS 7.0 及更高版本,只需勾选此项。

    self.edgesForExtendedLayout = UIRectEdgeNone;
    

    我希望它会工作......

    【讨论】:

      猜你喜欢
      • 2015-02-21
      • 1970-01-01
      • 2014-12-04
      • 2013-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-15
      相关资源
      最近更新 更多