How do I scale a UIButton's imageView?

前端 未结 19 2968
刺人心
刺人心 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:08

        UIButton *button= [[UIButton alloc] initWithFrame:CGRectMake(0,0,70,70)];
        button.buttonType = UIButtonTypeCustom;
        UIImage *buttonImage = [UIImage imageNamed:@"image.png"];
    
        UIImage *stretchableButtonImage = [buttonImage stretchableImageWithLeftCapWidth:12 topCapHeight:0]; 
        [button setBackgroundImage:stretchableButtonImage forState:UIControlStateNormal]; 
    

提交回复
热议问题