UIButton won't go to Aspect Fit in iPhone

后端 未结 21 2218
小鲜肉
小鲜肉 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:22

    I had this problem a while back. The issue I had was i was trying to apply this effect to the background UIButton which is limited and therefore means you cannot adjust it as easy.

    The trick is to set it as just an image then apply @ayreguitar's technique and that should fix it!

    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [myButton setContentMode:UIViewContentModeScaleAspectFill];
    [myButton setImage:@"myImage.png" forState:UIControlStateNormal];
    

提交回复
热议问题