Jump to content

Sam Emory

Members
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Sam Emory

  • Rank
    New Mac Geek
  1. Sam Emory

    Need help from an iphone developer

    Im trying to show the status of a todo item in this to do list app that I am Making but it wound show up please help! I high lighted the part that I am trying to show in red if you need to see the rest of the code let me know and I'll put it up here is the code that i was having trouble with: ------------------------------------------------------------------------------------------------------- #import "TodoCell.h" static UIImage *priority1Image = nil; static UIImage *priority2Image = nil; static UIImage *priority3Image = nil; @interface TodoCell() - (UILabel *)newLabelWithPrimaryColor:(UIColor *)primaryColor selectedColor: (UIColor *)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold; @end @implementation TodoCell @synthesize todoTextLabel,todoStatusLabel,todoPriorityLabel,todoPriorityImageView; + (void)initialize { // The priority images are cached as part of the class, so they need to be // explicitly retained. priority1Image = [[uIImage imageNamed:@"red.png"] retain]; priority2Image = [[uIImage imageNamed:@"yellow.png"] retain]; priority3Image = [[uIImage imageNamed:@"green.png"] retain]; } - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) { UIView *myContentView = self.contentView; self.todoPriorityImageView = [[uIImageView alloc] initWithImage:priority1Image]; [myContentView addSubview:self.todoPriorityImageView]; [self.todoPriorityImageView release]; self.todoStatusLabel = [self newLabelWithPrimaryColor:[uIColor blackColor] selectedColor:[uIColor whiteColor] fontSize:10.0 bold:YES]; self.todoStatusLabel.textAlignment = UITextAlignmentLeft; //default; [myContentView addSubview:self.todoStatusLabel]; [self.todoStatusLabel release]; self.todoTextLabel = [self newLabelWithPrimaryColor:[uIColor blackColor] selectedColor:[uIColor whiteColor] fontSize:14.0 bold:YES]; self.todoTextLabel.textAlignment = UITextAlignmentLeft; // default [myContentView addSubview:self.todoTextLabel]; [self.todoTextLabel release]; self.todoPriorityLabel = [self newLabelWithPrimaryColor:[uIColor blackColor] selectedColor:[uIColor whiteColor] fontSize:10.0 bold:YES]; self.todoPriorityLabel.textAlignment = UITextAlignmentRight; [myContentView addSubview:self.todoPriorityLabel]; [self.todoPriorityLabel release]; // Position the todoPriorityImageView above all of the other views so // it's not obscured. It's a transparent image, so any views // that overlap it will still be visible. [myContentView bringSubviewToFront:self.todoStatusLabel]; } return self; } - (Todo *)todo { return self.todo; } - (void)setTodo:(Todo *)newTodo { todo = newTodo; self.todoTextLabel.text = newTodo.text; self.todoPriorityImageView.image = [self imageForPriority:newTodo.priority]; switch(newTodo.priority) { case 2: self.todoPriorityLabel.text = @"Medium"; break; case 3: self.todoPriorityLabel.text = @"Low"; break; default: self.todoPriorityLabel.text = @"High"; break; } [self setNeedsDisplay]; } - (void)layoutSubviews { #define LEFT_COLUMN_OFFSET 2 #define LEFT_COLUMN_WIDTH 50 #define RIGHT_COLUMN_OFFSET 75 #define RIGHT_COLUMN_WIDTH 240 #define UPPER_ROW_TOP 40 [super layoutSubviews]; CGRect contentRect = self.contentView.bounds; if (!self.editing) { CGFloat boundsX = contentRect.origin.x; CGRect frame; // Place the status label. frame = CGRectMake(boundsX +LEFT_COLUMN_OFFSET , UPPER_ROW_TOP, LEFT_COLUMN_WIDTH, 13); frame.origin.y = 40; self.todoStatusLabel.frame = frame; // Place the Text label. frame = CGRectMake(boundsX +RIGHT_COLUMN_OFFSET , UPPER_ROW_TOP, RIGHT_COLUMN_WIDTH, 13); frame.origin.y = 10; self.todoTextLabel.frame = frame; // Place the priority image. UIImageView *imageView = self.todoPriorityImageView; frame = [imageView frame]; frame.origin.x = boundsX + LEFT_COLUMN_OFFSET; frame.origin.y = 10; imageView.frame = frame; } } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; UIColor *backgroundColor = nil; if (selected) { backgroundColor = [uIColor clearColor]; } else { backgroundColor = [uIColor whiteColor]; } self.todoTextLabel.backgroundColor = backgroundColor; self.todoTextLabel.highlighted = selected; self.todoTextLabel.opaque = !selected; self.todoPriorityLabel.backgroundColor = backgroundColor; self.todoPriorityLabel.highlighted = selected; self.todoPriorityLabel.opaque = !selected; } - (UILabel *)newLabelWithPrimaryColor:(UIColor *)primaryColor selectedColor:(UIColor *)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold { UIFont *font; if (bold) { font = [uIFont boldSystemFontOfSize:fontSize]; } else { font = [uIFont systemFontOfSize:fontSize]; } UILabel *newLabel = [[uILabel alloc] initWithFrame:CGRectZero]; newLabel.backgroundColor = [uIColor whiteColor]; newLabel.opaque = YES; newLabel.textColor = primaryColor; newLabel.highlightedTextColor = selectedColor; newLabel.font = font; return newLabel; } - (UIImage *)imageForPriority:(NSInteger)priority { switch (priority) { case 2: return priority2Image; break; case 3: return priority3Image; break; default: return priority1Image; break; } return nil; } - (void)dealloc { [super dealloc]; } @end
×