本文介绍了你可以硬编码IBActions和IBOutlet,而不是在Interface Builder中手动拖动它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在代码中硬编码 IBAction s和 IBOutlet ,而不是拖动连接

Is it possible to to hard code the IBActions and IBOutlets in code, instead of drag-connecting them in Interface Builder?

推荐答案

是的,它是poosible ...

Yes it is poosible...

示例代码

UIButton *btnDetail = [UIButton buttonWithType:UIButtonTypeRoundedRect] ;

        [btnDetail setFrame:CGRectMake(250.0f, 15.0f, 65.0f, 20.0f)] ;
        //btnDetail.backgroundColor = [UIColor grayColor];
        [btnDetail setTitle:@"Detail" forState:UIControlStateNormal];
        [btnDetail setTitleColor: [UIColor redColor] forState: UIControlStateNormal];
        [btnDetail.titleLabel setFont:[UIFont fontWithName:@"Verdana" size:12]];
        [btnDetail setBackgroundColor:[UIColor clearColor]];
        [btnDetail sizeThatFits:btnDetail.frame.size];
        [self.view addSubview:btnDetail];
//IBAction
        [btnDetail addTarget:self
                   action:@selector(ShowSavingAccountDetail:)
         forControlEvents:UIControlEventTouchUpInside];

        [btnDetail setImage:[UIImage imageNamed:@"btn-detail.png"] forState:UIControlStateNormal];

这篇关于你可以硬编码IBActions和IBOutlet,而不是在Interface Builder中手动拖动它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 01:58