2012-12-05 5 views
1

을 변경합니다 :서브 클래스 UIActivityIndicator이 내가 무슨 짓을 이미지

@implementation BGUIActivityIndicator 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 
    } 
    [self customInitialize]; 
    return self; 
} 

-(id)initWithCoder:(NSCoder *)aDecoder 
{ 
    self = [super initWithCoder:aDecoder]; 
    [self customInitialize]; 
    return self; 
} 

-(void)customInitialize 
{ 
    UIView * theImageView= [self findASubViewforClass:[UIImageView class]];// 
    UIImageView * theImageView1 = (UIImageView *) theImageView; 
    theImageView1.image = [UIImage imageNamed:@"spinner_blue"]; 
    [theImageView1.image saveScreenshot]; 
    while (false) ; 
} 
/* 
// Only override drawRect: if you perform custom drawing. 
// An empty implementation adversely affects performance during animation. 
- (void)drawRect:(CGRect)rect 
{ 
    // Drawing code 
} 
*/ 

@end 

모든 것이 완벽한 것 같다. [theImageView1.image saveScreenshot]; 이전보기와 새보기 모두를 완벽하게 기록하십시오.

그러나 아무 것도 변경되지 않습니다. 왜?

UIActivityIndicator의 이미지를 변경하는 방법을 정확히 묻는 것은 아닙니다. 이미 그것의 톤이 있습니다. UIActivityIndicator를 서브 클래 싱하는 것이 가장 좋은 해결책이라고 생각하기 때문에 그것을 사용하고 싶습니다. 나는 그렇게 할 수 없다.

특히 검색 컨트롤러의 배경을 바꾸는 데 사용되는 방식이 왜 효과가 없는지 묻습니다.

답변

2

UIActivityIndicatorView Class Reference에 따르면 하위 분류를 통해 이미지를 변경할 수있는 방법/기회가 없습니다. 당신은, UIActivityIndicatorStyle 등 작동 표시등의 색을 그 activityIndicatorViewStyle을 변경할 수 있습니다 그러나

.. 내가 생각

는, 서브 클래스라는없이 클래스 클래스 있는 UIImageView 구현하는 매우 유용하고 간단한 방법을 제공 그런 것.

1.Provide a number of images that reflect your indicator animation. 
2.Create a new UIImageView instance and set images and animation duration. 
3.Position your custom activity indicator within your current view. 

샘플 코드 : 당신이해야 할 유일한 것은이다

//Create the first status image and the indicator view 
UIImage *statusImage = [UIImage imageNamed:@"status1.png"]; 
UIImageView *activityImageView = [[UIImageView alloc] 
       initWithImage:statusImage]; 


//Add more images which will be used for the animation 
activityImageView.animationImages = [NSArray arrayWithObjects: 
      [UIImage imageNamed:@"status1.png"], 
      [UIImage imageNamed:@"status2.png"], 
      [UIImage imageNamed:@"status3.png"], 
      [UIImage imageNamed:@"status4.png"], 
      [UIImage imageNamed:@"status5.png"], 
      [UIImage imageNamed:@"status6.png"], 
      [UIImage imageNamed:@"status7.png"], 
      [UIImage imageNamed:@"status8.png"], 
      nil]; 


//Set the duration of the animation (play with it 
//until it looks nice for you) 
activityImageView.animationDuration = 0.8; 


//Position the activity image view somewhere in 
//the middle of your current view 
activityImageView.frame = CGRectMake(
      self.view.frame.size.width/2 
       -statusImage.size.width/2, 
      self.view.frame.size.height/2 
       -statusImage.size.height/2, 
      statusImage.size.width, 
      statusImage.size.height); 

//Start the animation 
[activityImageView startAnimating]; 


//Add your custom activity indicator to your current view 
[self.view addSubview:activityImageView]; 

은 자세한 내용을 참조하십시오 Here

관련 문제