[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 , 100, 100)]; indicatorView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.7f]; [[UIApplication sharedApplication].keyWindow addSubview:indicatorView]; indicatorView.layer.cornerRadius = 10; [[indicatorView layer] setBorderWidth:1.0f]; [[indicatorView layer] setBorderColor:[UIColor whiteColor].CGColor]; indicatorView.clipsToBounds = YES; indicatorView.tag = 50;
activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(indicatorView.frame.size.width/2-15, 20, 30, 30)]; [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.width, 20)]; 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]
'iOS > Swift + Objective-c' 카테고리의 다른 글
[IOS] status bar text color 변경 (0) | 2017.08.11 |
---|---|
[ios xcode] error: linker command failed with exit code 1 (0) | 2017.05.25 |
[objective c] NSString contains string (0) | 2017.04.21 |
[iOS Objective c] 화면 흔들기 (view shake) 구현 (0) | 2017.03.31 |
[iOS Objective c] 진동 구현 (0) | 2017.03.31 |