Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

objective c - Can you hard code IBActions and IBOutlets, rather than drag them manually in Interface Builder?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes it is poosible...

sample code

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...