How to add a UIButton at runtime

前端 未结 5 1475
予麋鹿
予麋鹿 2020-12-31 05:23

I am trying to add a UIButton at runtime however it is not visible. What am I doing wrong?

- (id)initWithFrame:(CGRect)frame {
    if (self = [s         


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 05:29

    First check whether your code is executing the initwithFrame method. Because if you are loading the view from nib i.e using

    NSArray *xibviews = [[NSBundle mainBundle] loadNibNamed: @"MySubview" owner: mySubview options: NULL];
    MySubview *msView = [xibviews objectAtIndex: 0];
    [self.view addSubview:msView]; 
    

    Then the initWithFrame part will not be executing.So please check once.

提交回复
热议问题