How do I scale a UIButton's imageView?

前端 未结 19 2977
刺人心
刺人心 2020-12-02 05:16

I created a UIButton instance named \"button\" with an image using [UIButton setImage:forState:]. The button.frame is larger than the image\'s size.

Now

19条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 06:05

    Just do (From Design OR From Code):

    From Design

    1. Open your xib OR Storyboard.
    2. Select button
    3. Inside Attribute Inspector (Right side) > In "Control" section > select last 4th option for both Horizontal and Verical.

    [For Point#3: Change Horizontal and vertical Align to UIControlContentHorizontalAlignmentFill and UIControlContentVericalAlignmentFill]

    From Code

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

提交回复
热议问题