Skip to content

Instantly share code, notes, and snippets.

@randomweapon
Created May 23, 2012 04:15
Show Gist options
  • Save randomweapon/2773235 to your computer and use it in GitHub Desktop.
Save randomweapon/2773235 to your computer and use it in GitHub Desktop.
Alternating row colours in objective-c (modulo)
for ( int i = 0; i < 5; i++ )
{
UIView *subview = [[UIView alloc] initWithFrame:CGRectMake(0, 44 * i, self.view.frame.size.width, 44)];
// this is where the magic is done. Check to see if the number is dividable by 2 (modulo)
if ( i % 2 == 1 )
{
subview.backgroundColor = [UIColor blackColor];
}
[self.view addSubview:subview];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment