Adding a subview to UIButton

后端 未结 2 978
礼貌的吻别
礼貌的吻别 2020-12-19 10:13

I\'m trying to add a customBadge as a subview of a UIButton -

this is my code so far -

//msg count initiaition
//CustomBadge *customBadge1 = [Custom         


        
相关标签:
2条回答
  • 2020-12-19 10:32

    Issue is within your setFrame: method. You are using self.view.frame.size.width.

    Check with this code:

    [customBadge1 setCenter:CGPointMake(_MsgHeadBtn.frame.size.width, 0)];
    [_MsgHeadBtn addSubview:customBadge1];
    

    or

    [customBadge1 setFrame:CGRectMake(_MsgHeadBtn.frame.size.width, 0, customBadge1.frame.size.width, customBadge1.frame.size.height)];
    [_MsgHeadBtn addSubview:customBadge1];
    
    0 讨论(0)
  • 2020-12-19 10:32

    Adjust your frame like below:

    [customBadge1 setFrame:CGRectMake(_MsgHeadBtn.frame.size.width-customBadge1.frame.size.width,-customBadge1.frame.size.height/2, customBadge1.frame.size.width, customBadge1.frame.size.height)];
    
    0 讨论(0)
提交回复
热议问题