我在viewDidLoad中使用了此代码,但在加载图片之前未显示图片。
NSString *ImageString=@"http://images.all-free-download.com/images/graphiclarge/daisy_pollen_flower_220533.jpg";
UIImage *HeartImage=[UIImage imageNamed:@"Heart.png"];
UIImageView *HeartImageView=[[UIImageView alloc]initWithImage:HeartImage];
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.center=self.WebimageView.center;
activityIndicator.frame = CGRectMake(15, 15, 30, 30);
activityIndicator.hidesWhenStopped = YES;
activityIndicator.hidden = NO;
[activityIndicator startAnimating];
activityIndicator.center = CGPointMake(self.WebimageView.frame.size.width /2, self.WebimageView.frame.size.height/2);
// [HeartImageView addSubview:activityIndicator];
[self.WebimageView sd_setImageWithURL:[NSURL URLWithString:ImageString]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[self.WebimageView addSubview:activityIndicator];
答案 0 :(得分:1)
这应该有效:
UIImage *heartImage = [UIImage imageNamed:@"Heart.png"];
UIImageView *heartImageView = [[UIImageView alloc] initWithImage:heartImage];
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0, 0, 30, 30);
activityIndicator.hidesWhenStopped = YES;
[activityIndicator startAnimating];
[heartImageView addSubview:activityIndicator];
[self.view addSubview:heartImageView];
编辑:清理