Thursday, May 7, 2009
iPhone: Want to use Hex for UIColor?
Thursday, May 7, 2009
When you need to set basic colors to things in Objective-C, it's really easy:
//This works, but come on...However, if you want to be more specific normally you need to get the RGBA for the color and set it that way. That's time consuming especially if the color may be tweaked several times before the final is settled upon. In flash we can just use Hex. Now, with this little macro, you can too & it's a HUGE time saver:
cell.textColor = [UIColor grayColor];
#define UIColorFromRGB(rgbValue) [UIColor \Shazaam!!!
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (nil == cell) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cell"] autorelease];
}
cell.textColor = UIColorFromRGB(0x333333);
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.text = @"Testing 1 2 3";
}
Labels: iPhone, Objective-C
Comments:
There are currently 1 Comments: