Tuesday 15 January 2013

xcode - UIButton in collectionView doesn't retain highlighting -



xcode - UIButton in collectionView doesn't retain highlighting -

i have collectionview, total of cells single button in each. have custom class cell. when press button, highlights, , reverts normal (in maybe 0.5-1seconds.

-(uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { gridcontrolviewoutputcell * outputcell; outputcell = (gridcontrolviewoutputcell *)[collectionview dequeuereusablecellwithreuseidentifier:@"gridcontrolviewoutputcell" forindexpath:indexpath]; if(outputcell == nil) { outputcell = [[gridcontrolviewoutputcell alloc] init]; } outputcell.outputdelegate = self; outputcell.ioindex = indexpath.row; [outputcell.outputbutton setuserinteractionenabled:true]; [outputcell.outputbutton setadjustsimagewhenhighlighted:true]; [outputcell.outputbutton setadjustsimagewhendisabled:true]; [outputcell.outputbutton setbackgroundcolor:[uicolor clearcolor]]; [outputcell.outputbutton setbackgroundimage:[[uiimage imagenamed:@"btn_normal.png"] stretchableimagewithleftcapwidth:12 topcapheight:12] forstate:uicontrolstatenormal]; [outputcell.outputbutton setbackgroundimage:[[uiimage imagenamed:@"btn_pressed.png"] stretchableimagewithleftcapwidth:12 topcapheight:12] forstate:uicontrolstatehighlighted]; if([buttons count] > indexpath.row) { [buttons replaceobjectatindex:indexpath.row withobject:outputcell.outputbutton]; } else{ [buttons insertobject:outputcell.outputbutton atindex:indexpath.row]; } homecoming outputcell; } #import "gridcontrolviewoutputcell.h" @implementation gridcontrolviewoutputcell @synthesize outputdelegate; @synthesize ioindex; @synthesize outputbutton; - (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; homecoming self; } -(ibaction)buttonpressed:(id)sender { [outputdelegate outputchanged:ioindex on:true]; } -(ibaction)buttonreleased:(id)sender { [outputdelegate outputchanged:ioindex on:false]; } @end

buttonpressed tied touchdown

buttonreleased tied touch cancel, drag exit, touch within (although not sure need touch cancel)

the events fire expected, it's highlighting doesn't "stick" when button held.

edit: clear, i'm not trying maintain button highlighted after releasing it. there several questions on here relating that. i'm trying maintain highlighted while pressed.

xcode

No comments:

Post a Comment