`

在uiimageview中设置网络图片等比例大小

    博客分类:
  • ios
 
阅读更多
NSData *data=[NSData dataWithContentsOfURL:[YeehealthApi getServerImage:[dic objectForKey:@"images"]]];
        UIImage *img = [UIImage imageWithData:data];
        
        CGFloat realX;
        CGFloat realY;
        CGFloat _x;
        CGFloat _y;
        CGFloat _w;
        CGFloat _h;
        
        if (ScreenW>img.size.width) {
            realX = (ScreenW-img.size.width)/2.0;
            _x = realX+ScreenW*i;
            
            if (ScreenH>img.size.height) {
                realY = (ScreenH-img.size.height)/2.0;
                _y = realY;
                _w = img.size.width;
                _h = img.size.height;
            }else{
                _y = 0;
                _w = img.size.width/(img.size.height/ScreenH);
                _h = img.size.height/(img.size.height/ScreenH);
            }
            
        }else{
             _x = ScreenW*i;
            if (ScreenH>img.size.height) {
                realY = (ScreenH-img.size.height)/2.0;
                _y = realY;
                _w = img.size.width/(img.size.width/ScreenW);
                _h = img.size.height/(img.size.width/ScreenW);
            }else{
                _y = (ScreenH-img.size.height/(img.size.width/ScreenW))/2;
                _w = img.size.width/(img.size.width/ScreenW);
                _h = img.size.height/(img.size.width/ScreenW);
            }
        }
        
        imgV.frame = CGRectMake(_x,_y,_w, _h);
]
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics