UIButton doesn't listen to content mode setting?

后端 未结 16 2102
情话喂你
情话喂你 2020-12-02 08:45

firstButton is a UIButton of type Custom. I\'m programmatically putting three of them across each cell of a table, thusly:

[firstButton setImage:markImage fo         


        
16条回答
  •  失恋的感觉
    2020-12-02 09:26

    My answer is similar to Kuba's. I needed my image to be programatically set.

    UIImage *image = [[UIImage alloc] initWithContentsOfFile:...];
    [button setBackgroundImage:image forState:UIControlStateNormal];
    button.imageView.contentMode = UIViewContentModeScaleAspectFill; //this is needed for some reason, won't work without it.
    for(UIView *view in button.subviews) {
        view.contentMode = UIViewContentModeScaleAspectFill;
    }
    

提交回复
热议问题