.h文件:
#import <UIKit/UIKit.h>
@interface ViewController :UIViewController{
UIButton *sourceBt;
}
@property(nonatomic,retain)IBOutletUIButton *sourceBt;
-(IBAction)select:(id)sender;
@end
.m文件
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)select:(id)sender
{
if (self.sourceBt)
{
self.sourceBt.selected =NO;
self.sourceBt.backgroundColor=[UIColorwhiteColor];
}
UIButton * bt = (UIButton *)sender;
bt.selected =YES;
bt.backgroundColor=[UIColorredColor];
self.sourceBt = bt;
NSLog(@"%d",bt.tag); //获取选择的btn的tag值
}
@end