UIButton with both image and text possible?

前端 未结 10 1538
轮回少年
轮回少年 2020-12-02 08:57

I have a button of size width 200 and height 270. I want to have text and image on the same button. Not as a background image on that text. Instead of this, I want to displa

10条回答
  •  清歌不尽
    2020-12-02 09:16

    You can use this code,it will serve your purpose

    .h file code
    IBOutlet UIButton *testBtn;
    
    .m file code
    [testBtn setImage: [UIImage imageNamed:@"Image name.png"] forState:UIControlStateNormal];
    [testBtn setTitleEdgeInsets:UIEdgeInsetsMake(70.0, -150.0, 5.0, 5.0)];
    [testBtn setTitle:@"Your text" forState:UIControlStateNormal];
    

    Adjust the coordinates and size of your button as your requirement.This is a sample code to guide you.

    PS:Take a UIButton in the nib file>Make it a custom button>Connect the IBOutlet to your custom button in the nib file.Thats it.

提交回复
热议问题