UIButton of type UIButtonTypeCustom will not display Title (iPhone)

后端 未结 5 1684
栀梦
栀梦 2020-12-08 09:21

I must have overlooked something completely obvious?? but my button displays its image and size correctly, but I simply can\'t get the Title to show up.

I did a real

相关标签:
5条回答
  • 2020-12-08 10:06

    I just hab spome quite similar problem... Just set the title color, I guess the current one is white ;)

    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    0 讨论(0)
  • 2020-12-08 10:06

    I found the problem!

    It's not Image overriding the title. It is being push off frame by the image.

    Try use this:

    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0.0, -img.size.width, 0.0, 0.0 )];

    Hope it helps!

    0 讨论(0)
  • 2020-12-08 10:15

    When you use UIButton, button uses some built-in size for its frame.

    You should set the frame:

    button.frame = CGRectMake(0, 0, width, height);
    

    or even better and comfortable:

    [button sizeToFit];
    
    0 讨论(0)
  • 2020-12-08 10:17

    I had a similar problem that the title was not shown. I forgot to set the frame property:

    //set the position of the button
    button.frame = CGRectMake(100, 170, 100, 30);
    
    0 讨论(0)
  • 2020-12-08 10:21

    Image overrides title, you need to make the image a background image to show the title.

    [button setBackgroundImage:[UIImage imageNamed:@"left_halfscreen_button.png"] 
            forState:UIControlStateNormal];
    
    0 讨论(0)
提交回复
热议问题