iOS/Swift + Objective-c

[iOS objective-c] indicator 사용하기

안경 쓴 귀니 2017. 4. 27. 10:13
반응형






[iOS objective-c] indicator 사용하기





 1. 만들 때

 UIView *indicatorView;

        UIActivityIndicatorView *activityIndicator;

        UILabel *labelLoading;

        

        indicatorView = [[UIView alloc]initWithFrame:CGRectMake([UIApplication sharedApplication].keyWindow.frame.size.width/2-50, [UIApplication sharedApplication].keyWindow.frame.size.height/2-30 , 100100)];

        indicatorView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.7f];

        [[UIApplication sharedApplication].keyWindow addSubview:indicatorView];

        indicatorView.layer.cornerRadius = 10;

        [[indicatorView layersetBorderWidth:1.0f];

        [[indicatorView layersetBorderColor:[UIColor whiteColor].CGColor];

        indicatorView.clipsToBounds = YES;

        indicatorView.tag = 50;

        

        activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(indicatorView.frame.size.width/2-15203030)];

        [activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];

        activityIndicator.tag = 51;

        //activityIndicator.backgroundColor=[UIColor greenColor];

        [indicatorView addSubview:activityIndicator];

        [activityIndicator startAnimating];

        

        labelLoading = [[UILabel alloc]initWithFrame:CGRectMake(0, indicatorView.frame.size.height-30, indicatorView.frame.size.width20)];

        labelLoading.text = @"Loading...";

        labelLoading.textColor = [UIColor whiteColor];

        labelLoading.textAlignment = NSTextAlignmentCenter;

        labelLoading.font = [UIFont fontWithName:@"YanaR-Bold" size:11];

        labelLoading.tag = 52;

        //    [labelLoading setFont:[UIFont boldSystemFontOfSize:12.0f]];

        [indicatorView addSubview:labelLoading];




2. 없앨 때

 UIView *indicatorView;

        UIActivityIndicatorView *activityIndicator;

        UILabel *labelLoading;

        

        indicatorView = [[UIApplication sharedApplication].keyWindow viewWithTag:50];

        activityIndicator = [indicatorView viewWithTag:51];

        labelLoading = [indicatorView viewWithTag:52];

        [labelLoading removeFromSuperview];

        [activityIndicator removeFromSuperview];

        [indicatorView removeFromSuperview];




[출처 : http://stackoverflow.com/questions/19475350/add-an-activity-indicator-on-a-uiwebview]




반응형