iOS: SVProgressHUD not displaying in centre when i use setContainerView

2.2k Views Asked by At

I am using SVProgressHUD for loader. When i use setContainerView method the loader is not displaying in centre. Can any one help me out.

Used below code to show Loader

 + (void)showLoadingHUDForView:(UIView *)view {
    if (view != nil) {
        [SVProgressHUD setRingThickness:3.0];
        [SVProgressHUD setContainerView:requiredView];
        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
        [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
        [SVProgressHUD show];
    }
}
1

There are 1 best solutions below

0
On

The solution is to set the progressHUD's offset from center, like so:

let containerOrigin = requiredView.origin
SVProgressHUD.setOffsetFromCenter(UIOffset(horizontal: -containerOrigin.x, vertical: -containerOrigin.y))

If your requiredView is contained in another view, you will have to take in consideration all the parent views in the hierarchy, because progressHUD offset seems to be relative to the app's window.