ios - UIWindow 整个应用程序的圆角

标签 ios cocoa window rounded-corners mask

我想在我的应用程序的边缘(整个应用程序)有小圆角,所以我认为最好的位置是在主 UIWindow 层上创建于AppDelegate类(class)。这是我的代码...

[self.window.layer setCornerRadius:30.0f];
[self.window.layer setMasksToBounds:YES];

这确实使我的窗口底部的角变圆,并且在顶部稍微变圆。然而,窗口是屏幕的完整尺寸(不是屏幕减去状态栏),所以我最终得到这样的结果.. http://tfld.me/image/441U0j3w3X3N

我真的不想在我的应用程序中的所有导航 Controller / View 的每个图层上添加cornerRadius/masksToBounds选项..或者有一个背景图像(因为这不太适合 future )。

我也尝试在 Windows rootViewController 上设置这些选项,但没有成功 - http://tfld.me/image/0c1m2w36402K

非常感谢任何建议:)

最佳答案

如果您希望导航栏弯曲,您可以使用适当的图像。如果没有,那么下面的代码应该可以根据您的需要工作:

    self.window = [[[UIWindow alloc] init] autorelease];
    //shift the window frame by 20 px so that it goes below status bar
    CGRect sampleRect = [[UIScreen mainScreen] bounds];
    sampleRect.origin.y += 20.0;
    sampleRect.size.height -= 20.0;
    self.window.frame = sampleRect;

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.frame = [[UIScreen mainScreen] bounds];

    UINavigationController *mRootController = [[UINavigationController alloc] initWithRootViewController:vc];
    CGRect navFrame = mRootController.view.frame;
    navFrame.origin.y -= 20.0; //Shift the navigation frame up by 20 px
    mRootController.view.frame = navFrame;

    [self.window addSubview:mRootController.view];
    [self.window.layer setCornerRadius:20.0f];
    [self.window.layer setMasksToBounds:YES];

关于ios - UIWindow 整个应用程序的圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12332992/

相关文章:

ios - 如何设置 iOS Telegram 源代码

macos - Cocoa osx NSSharingServicePicker 设置默认电子邮件地址

objective-c - WKWebView 在不重新加载页面的情况下评估 Javascript

在 UIViewController 中带有自定义原型(prototype)单元格的 iOS 表格 View

ios - 如何通过3点画圆弧

ios - 获取 curl : (22) The requested URL returned error: 403 Forbidden while installing linphone through cocoa pods?

macos - Cocoa NSCollectionView 不调用 dataSource 方法

wpf - 如何使调整 WPF 窗口的大小减少 "laggy"?

ios - 如何创建穿过一层进入另一层的窗口

javascript - 无法使用 JavaScript 将自定义属性添加到窗口对象