2015-12-04 140 views
0

我有一些base64數據,並試圖把它放在我的圖像,我可以做但我無法得到它,因此它縮小到只填充imageView,而不是使它更大,這裏是我在做什麼圖像不適合UIImageView

NSString *base64 =[[NSString stringWithFormat:@"data:image/png;base64,%@", dataString] stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 
    NSURL *url = [NSURL URLWithString:base64]; 
    NSData *imageData = [NSData dataWithContentsOfURL:url]; 
    UIImage *image = [UIImage imageWithData:imageData]; 
    rdCell.imageView.clipsToBounds = YES; 
    rdCell.imageView.contentMode = UIViewContentModeScaleAspectFill; 
    [rdCell.imageView setImage:image]; 

我也試過這種

 NSURL *url = [NSURL URLWithString:base64]; 
    NSData *imageData = [NSData dataWithContentsOfURL:url]; 
    UIImage *image = [UIImage imageWithData:imageData]; 
    rdCell.imageView.contentMode = UIViewContentModeScaleAspectFit; 
    [rdCell.imageView setImage:image]; 

但後來我看到圖像比圖像視圖的原始尺寸大,爲什麼不會它留在裏面?

謝謝

+0

是什麼rdCell?告訴我們你在哪裏分配imageView? –

+0

@SamB rdCell是我的UITableViewCell包含圖像視圖,我將發佈更多關於它上面 – spenf10

回答

0

您必須改用contentMode UIViewContentModeScaleAspectFit

+0

我想,也和 – spenf10

+0

@ spenf10你爲什麼要接受一個答案,說明它沒有工作後,沒有工作? – rmaddy

0

UIViewContentModeScaleToFill應該做的伎倆,但你必須確保你能夠看到整個圖像視圖顯示在屏幕上,並給予一定的內容大小會有所幫助。