UIActivityIndicatorView와 메시지를 표시하기 위해 사용자 정의 UIView를 만들었습니다. 아이디어 일관성을 위해 내 애플 리케이션에 걸쳐 이것을 재사용하는 것입니다.사용자 정의 UIView가 스토리 보드에 서브 뷰를 표시하지 않습니다.
@implementation CDActivityIndicator
@synthesize activityIndicator, message;
//init method called when the storyboard wants to instantiate this view
- (id) initWithCoder:(NSCoder*)coder {
if ((self = [super initWithCoder:coder])) {
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
message = [[UILabel alloc] initWithFrame:CGRectZero];
[message setBackgroundColor:[UIColor clearColor]];
[message setTextColor:[UIColor whiteColor]];
[message setTextAlignment:NSTextAlignmentCenter];
[message setFont:[UIFont fontWithName:@"HelveticaNeue" size:15.0f]];
[self addSubview:activityIndicator];
[self addSubview:message];
//set background color
[self setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5]];
}
return self;
}
-(void) layoutSubviews {
[super layoutSubviews];
//position the indicator at the center of the view
[activityIndicator setCenter:[self center]];
//position the label
[message setFrame:[self frame]];
}
- (void) begin {
//make sure the current view is visible, and message is hidden
[self setHidden:NO];
[activityIndicator setHidden:NO];
[self bringSubviewToFront:activityIndicator];
[message setHidden:YES];
[self performSelectorOnMainThread:@selector(startAnimating) withObject:self waitUntilDone:YES];
}
- (void) startAnimating {
if(!activityIndicator.isAnimating) {
[activityIndicator startAnimating];
}
}
나는 스토리 보드 내보기 중 하나에 UIView의 추가, 이것을 시도하고 CDActivityIndicator에 해당 뷰의 클래스를 설정하려면 : 아래는 코드입니다. 해당 View Controller에서 begin()을 호출하면 CDActivityIndicator가 예상 배경색의 빈보기로 표시됩니다. 그러나 활동 표시기는 표시되지 않습니다. 모든 메소드가 예상대로 호출됩니다.
제가 누락 된 것일 수도 있습니다. 감사!
활동 표시기에 대한 전체 코드를 추가 할 수 있습니까? – Sam