How can I addSubview to UIButton in Interface Builder

后端 未结 4 1726
轻奢々
轻奢々 2021-02-18 22:57

Like I said, I add a UIButton in Interface Builder, I want add a UILabel、UIImageView as the button\'s subviews, but I can\'t add any object on it in IB. IS anybody know how to d

4条回答
  •  青春惊慌失措
    2021-02-18 23:44

    instead of UIButton, add the UILabel and UIImageView to UIView and then add a tap action to it.

    EDIT 1:

    it's easy to change make a highlighted color effect, use the following code:

    - (void) onViewTap:(id)sender
    {
        [UIView animateWithDuration:0.1
                              delay:0
                            options:UIViewAnimationOptionCurveEaseOut
                         animations:^{
                             _view.backgroundColor = [UIColor blueColor];
                         }
    
                         completion:^(BOOL finished){
                             _view.backgroundColor = [UIColor whiteColor];
                         }];
    
        //write tap actions below
    }
    - (void)viewDidLoad
    {
        _view.userInteractionEnabled = YES;
        UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onViewTap:)];
        [_view addGestureRecognizer:tap];
    }
    

提交回复
热议问题