UIButton doesn't listen to content mode setting?

后端 未结 16 2122
情话喂你
情话喂你 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:21

    If you're dealing with the UIButton's image (as opposed to it's backgroundImage), setting the contentMode on the UIButton itself or on its imageView has no effect (despite what other answers say).

    Alternatively do this instead:

    self.button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
    self.button.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
    

    Or size your image accordingly.

    OR just use a UIImageView (which properly respects contentMode) with a UITapGestureRecognizer attached to it, or a transparent UIButton on top of it.

提交回复
热议问题