Programmatically set image and text on UIButton

后端 未结 6 1760
孤街浪徒
孤街浪徒 2020-12-28 13:46

I need to create button programatically with an image for normal and highlighted state as well text. I cannot build it using Interface Builder, because I need to create butt

6条回答
  •  遥遥无期
    2020-12-28 13:54

    You've made a mistake there, you're doing

    [btn setBackgroundImage:buttonImage forState:UIControlStateNormal]; 
    

    instead of

    [btn setImage:buttonImage forState:UIControlStateNormal]; 
    

    This will work fine.

提交回复
热议问题