0

これは私がしたことです:

@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]; 古いビューと新しいビューの両方を完全に書き留めます。

ただし、何も変わりません。なんで?

UIActivityIndi​​catorの画像を変更する方法を正確に尋ねているわけではありません。すでにたくさんあります。UIActivityIndi​​catorをサブクラス化して使用したいのは、これが最も洗練されたソリューションだと思うからです。私はそれをすることができないようです。

特に、たとえば検索コントローラーの背景を変更するために機能する私のアプローチが、なぜこれに機能しないのかを尋ねています。

4

1 に答える 1

2

UIActivityIndi​​catorViewクラスリファレンスによると、サブクラス化によって画像を変更する方法/機会はありません。

ただし、そのactivityIndi​​catorViewStyle、アクティビティインジケーターの色、UIActivityIndi​​catorStyleなどを変更できます。

サブクラス化せずに、クラスクラス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];

詳細はこちらをご覧ください

于 2012-12-05T08:27:40.850 に答える