为整个应用程序应用圆角

时间:2012-01-05 00:13:51

标签: ios core-graphics calayer

如何在屏幕截图中显示应用于整个视图的圆角(请注意,导航栏和键盘角都是圆角的)?

我已尝试为cornerRadius = 10masksToBounds = YES设置window.layerwindow.rootViewController.view.layer,但只有底部视角变圆,导航栏仍保持方形。

更新cornerRadius设置为window.layer实际上也会在顶部添加圆角,但在状态栏下看不到这些角,除非cornerRadius大于20。

Example

4 个答案:

答案 0 :(得分:17)

好的,我在Twitter上问过 Twittelator Neue 的开发者Andrew Stone,这是他的食谱,在Andrew的允许下发布:

  

我们要写一本关于Neue编码技巧的书!我们在一个窗口上覆盖一个包含4个角落的图像

     

我们还有一个自定义导航栏,其中包含一个带有顶部圆形

的可伸缩图像

所以这就是我在自己项目中的表现:

UIImage *overlayImg = [UIImage imageNamed:@"overlay.png"];
CALayer *overlay = [CALayer layer];
overlay.frame = CGRectMake(0, 0, overlayImg.size.width, overlayImg.size.height);
overlay.contents = (id)overlayImg.CGImage;
overlay.zPosition = 1;
[self.window.layer addSublayer:overlay];

overlay.png是带有黑角的透明全屏图像。

答案 1 :(得分:1)

他们可能在导航栏上使用包含圆角的背景图像。

答案 2 :(得分:1)

iHunter的回答对我很有用,除非我尝试使用显示键盘而不是推文视图的TWTweetComposeViewController。然后,我应该将叠加层设置为AppDelegate.h中的属性,然后在tweetView之前删除叠加层。完成推文后,再次添加叠加。

AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.overlay removeFromSuperlayer];
TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc] init];
tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result) {
    AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    [delegate.window.layer addSublayer:delegate.overlay];
};
[self presentModalViewController:tweetSheet animated:YES];

答案 3 :(得分:0)

我怀疑窗户有圆角,因为我不相信状态栏的高度超过20个单位。我怀疑窗口只是设置了黑色背景(或者需要任何颜色来匹配状态栏,然后另一个视图放在顶部。顶部的视图有圆角。类似地,任何其他子视图都会有圆角帮助这种错觉的角落。

相关问题