我想在我的应用程序的边缘(整个应用程序)有小圆角,所以我认为最好的位置是在主 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/