我正在嘗試在表格單元格的左側添加一個圓圈,但無法找出最佳方式來做到這一點。我嘗試添加iOS:用iPhone日曆列表中的背景色製作圓圈
CGContextRef context= UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetAlpha(context, 0.5);
CGContextFillEllipseInRect(context, CGRectMake(10.0, 10.0, 10.0, 10.0));
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextStrokeEllipseInRect(context, CGRectMake(10.0, 10.0, 10.0, 10.0));
我的cellForRowAtIndexPath但保持無效的上下文錯誤。這是我的cellForRowAtIndexPath。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"AppointmentCell";
NSDictionary *appointment = [[self.appointments objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
int minutes = (int)[[NSString stringWithFormat:@"%@", [appointment objectForKey:@"start_time"]] integerValue];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"h:mma"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
NSDate *midnight = [NSDate dateWithTimeIntervalSince1970:0];
NSDate *newDate = [midnight dateByAddingTimeInterval:minutes*60];
NSString *newTime = [dateFormatter stringFromDate:newDate];
dateFormatter = nil;
cell.textLabel.text = newTime;
cell.detailTextLabel.textAlignment = UITextAlignmentCenter;
cell.detailTextLabel.text = [appointment objectForKey:@"reason"];
return cell;
}
我該如何將顏色添加到iPhone的日曆列表視圖?
不能回答你的問題,但你絕對應該使dateFormatter成爲該類的一個屬性。每次顯示單元格時都會創建一個新的NSDateFormatter。這不是必要的,對於性能來說非常糟糕。 – 2012-02-07 20:39:34
會做,謝謝 – Bot 2012-02-07 20:50:44