Created
May 23, 2012 04:15
-
-
Save randomweapon/2773235 to your computer and use it in GitHub Desktop.
Alternating row colours in objective-c (modulo)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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