UIImage Aspect Fit when using drawInRect?

后端 未结 6 1192
囚心锁ツ
囚心锁ツ 2020-12-13 18:51

UIView provides for the \"aspect fit\" content mode. However, I\'ve subclasses UIView and would like to draw a UIImage using drawInRect with an aspect fit. Is there any way

6条回答
  •  猫巷女王i
    2020-12-13 19:27

    this might help you, give it a try

    UIImage *logoImage = [UIImage imageNamed:@"logo.png"];
    
    float newHeight = ((logoImage.size.height / logoImage.size.width) * 100.0);
    CGRect newLogoImageRect = CGRectMake(0, 0, 80.0, newHeight);
    [logoImage drawInRect:newLogoImageRect];
    

    specify your maximum height instead of 100.0 and maximum width instead of 80.0

提交回复
热议问题