简体   繁体   中英

Rounded screen corners throughout the app with status bar

How can I achieve rounded corners on the screen while still displaying the status bar?

In the application delegate I am applying these settings to the window:

[self.window.layer setCornerRadius:10.0];
[self.window.layer setMasksToBounds:YES];
self.window.layer.opaque = NO;

but at the top of the screen I am not seeing the rounded corner because of the status bar. This is a problem because I need the status bar in the app too.

Can anyone suggest how I may fix this?

If you want to keep the status bar and still see the rounded edges, you'll have to round the edges of the view instead of the window.

In which case, you're code would be almost identical but applied to the view instead:

[self.view.layer setCornerRadius:10.0];
[self.view.layer setMasksToBounds:YES];
self.view.layer.opaque = NO;

This would go in the view controller.

Do you want to remove the status bar? Or are you trying to round the corners of the status bar? If you are wanting to round the corners of the status bar, the quick and simple answer is that you cannot. If you want to remove the status bar, this is quick and easy:

From Apple Class Reference:

setStatusBarHidden:withAnimation:

Hides or shows the status bar, optionally animating the transition. - (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation Parameters

hidden YES to hide the status bar, NO to show the status bar.

animation A constant that indicates whether there should be an animation and, if one is requested, whether it should fade the status bar in or out or whether it should slide the status bar in or out.

Add the below line in the viewWillAppear method. It will give a rounded lookNfeel for the view. For this include the 'QuartzCore` framework.

self.view.layer.cornerRadius = 10.0

Hope this might help you.

I know this question is old, but just put

func applicationDidBecomeActive(_ application: UIApplication) {
    window?.layer.cornerRadius = 10
    window?.clipsToBounds = true
    window?.backgroundColor = UIColor.black
}

in your AppDelegate.swift and you have rounded corners everywhere in your app :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM