iphone - How do I get a UIButton to change its color by clicking it? -
i want make app iphone. nonogram similar this: http://www.puzzle-nonograms.com/ how can make uibuttons changes color white black , reverse?
.h file
uibutton *button; bool clicked;
.m file - (void)viewdidload
{ [super viewdidload]; // additional setup after loading view, typically nib. clicked=yes; button = [uibutton buttonwithtype:uibuttontyperoundedrect]; [button addtarget:self action:@selector(changebtncolor) forcontrolevents:uicontroleventtouchdown]; [button settitle:@" 1 " forstate:uicontrolstatenormal]; button.frame = cgrectmake(80.0, 210.0, 160.0, 40.0); [button settitlecolor:[uicolor graycolor] forstate:uicontrolstatenormal]; [self.view addsubview:button]; } -(void)changebtncolor{ if (clicked) { [button settitlecolor:[uicolor redcolor] forstate:uicontrolstatenormal]; clicked=no; } else{ [button settitlecolor:[uicolor graycolor] forstate:uicontrolstatenormal]; clicked=yes; } }
i hope help. best of luck..
Comments
Post a Comment