UIButton won't go to Aspect Fit in iPhone

后端 未结 21 2266
小鲜肉
小鲜肉 2020-12-23 02:47

I have a couple UIButtons, and in IB they\'re set to Aspect Fit, but for some reason they\'re always stretching. Is there something else you have to set? I tried all the d

21条回答
  •  渐次进展
    2020-12-23 03:06

    Use button's imageView for contentMode. Not directly on the button itself.

    homeButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
    homeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
    homeButton.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
    [homeButton setImage:[UIImage imageNamed:kPNGLogo] forState:UIControlStateNormal];
    

提交回复
热议问题