- Create a UIButton called ‘pressHere’ that has nonatomic and weak property.
@property (nonatomic, weak) IBOutlet UIButton *pressHere;
IBOutletmakes Interface Builder recognize the outlet
weakis used because in most situations the owner of the outlet isn’t the same as the owner of the view. For example, a view controller doesn’t own
someLabel– the view controller’s
2. Set the background color for that button
pressHere.backgroundColor = [UIColor clearColor];
3. Set a title for the button
[pressHere setTitle:@”Click” forState:UIControlStateNormal];
4. Add an action for the button
[pressHere addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside];
Notice that “butClick” is a -(void) that has been defined somewhere else in the .m file.
How to add an action for a button in StoryBoard?