UIButton doesn't listen to content mode setting?

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

    After a couple of hours of confusion, here's how I got it to work under iOS 3.2. As dusker mentioned, using setBackgroundImage instead of setImage did the job for me.

    CGRect myButtonFrame = CGRectMake(0, 0, 250, 250);
    UIImage *myButtonImage = [UIImage imageNamed:@"buttonImage"];
    
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [myButton setBackgroundImage:myButtonImage forState:UIControlStateNormal];
    [myButton setFrame: myButtonFrame];
    [myButton setContentMode: UIViewContentModeScaleAspectFit];
    

提交回复
热议问题