ios - How do I access a button in a subview -
i want implement fade in/out in horizontal scroll have, can't figure out how access button in subview of uiscrollview. i'm trying implement fade in/out stackoverflow.
this code...
game *game = (game *)[_schedule.games objectatindex:i]; uibutton *button = [[uibutton alloc] initwithframe:cgrectmake(x, 20, 150, 100)]; [button setbackgroundimage:[uiimage imagenamed:game.opponent] forstate:uicontrolstatenormal]; //[button settitle:game.opponent forstate:uicontrolstatenormal]; [_gamescrolllist addsubview:button];
how can add observer button, can done?
[self.scrollview addobserver:[self.contentviews objectatindex:i] forkeypath:@"contentoffset" options:nskeyvalueobservingoptionnew context:@selector(updatealpha:)];
to access reference of button added subview, can:
use button ivar, saving reference use later;
similarly, use button property;
iterate through subviews of _gamescrolllist, looking subview of uibutton's class (not recommended, work if has 1 uibutton subview)
example of how implement second approach. declare property:
@property(nonatomic, strong) uibutton *button;
and then:
game *game = (game *)[_schedule.games objectatindex:i]; self.button = [[uibutton alloc] initwithframe:cgrectmake(x, 20, 150, 100)]; [self.button setbackgroundimage:[uiimage imagenamed:game.opponent] forstate:uicontrolstatenormal]; //[self.button settitle:game.opponent forstate:uicontrolstatenormal]; [_gamescrolllist addsubview:self.button];
so, after, when want access button somewhere, call property
self.button.alpha = 0.5; //example of interation button
if not looking for, should edit question more clear.
hope helped.
Comments
Post a Comment