为此,我使用了一个小 png 文件,其中包含 1/4 的透明圆(其半径将是窗口的新半径)和朝向角落的黑色(设计师向我提供了图像,您可能必须这样做你自己)。我imageView
使用这个 png 创建了 4 个,相应地旋转它们并将它们作为子视图添加到navigationController
.
将以下方法放入您的并在: 初始化后appDelegate
调用它。application:didFinishLaunchingWithOptions
navigationController
-(void) insertCornerRadiiOnNavigationController : (UINavigationController *) navController{
CGFloat cornerRadius = 7;
UIImageView *corner1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, cornerRadius, cornerRadius)];
UIImageView *corner2 = [[UIImageView alloc] initWithFrame:CGRectMake([_window bounds].size.width - cornerRadius, 20, cornerRadius, cornerRadius)];
UIImageView *corner3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, [_window bounds].size.height - cornerRadius, cornerRadius, cornerRadius)];
UIImageView *corner4 = [[UIImageView alloc] initWithFrame:CGRectMake([_window bounds].size.width - cornerRadius, [_window bounds].size.height - cornerRadius, cornerRadius, cornerRadius)];
corner2.transform = CGAffineTransformMakeRotation (M_PI_2);
corner3.transform = CGAffineTransformMakeRotation (3 * M_PI_2);
corner4.transform = CGAffineTransformMakeRotation (M_PI);
[corner1 setImage:[UIImage imageNamed:@"corner.png"]];
[corner2 setImage:[UIImage imageNamed:@"corner.png"]];
[corner3 setImage:[UIImage imageNamed:@"corner.png"]];
[corner4 setImage:[UIImage imageNamed:@"corner.png"]];
[navController.navigationBar addSubview:corner1];
[navController.navigationBar addSubview:corner2];
[navController.view addSubview:corner3];
[navController.view addSubview:corner4];
[corner1 release];
[corner2 release];
[corner3 release];
[corner4 release];
}
由于某种原因,我无法UIWindow
直接将它们添加到,imageViews
没有出现。