添加按鈕
#pragma mark 添加按鈕 - (void)addButtonWithImage:(NSString *)image highImage:(NSString *)highImage disableImage:(NSString *)disableImage frame:(CGRect)frame tag:(NSInteger)tag action:(SEL)action { // 創建按鈕 UIButton *btn = [[UIButton alloc] init]; // 設置背景圖片 [btn setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal]; [btn setBackgroundImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted]; [btn setBackgroundImage:[UIImage imageNamed:disableImage] forState:UIControlStateDisabled]; // 設置位置和尺寸 btn.frame = frame; // 監聽按鈕點擊 [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside]; // 綁定tag標記 btn.tag = tag; // 添加按鈕 [self.view addSubview:btn]; }