Last active
December 10, 2015 23:19
-
-
Save pyanfield/4508932 to your computer and use it in GitHub Desktop.
display the contact list as default phone book.
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
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | |
{ | |
Contact* contact = [self.contacts objectAtIndex:indexPath.row]; | |
UITableViewCell *cell = nil; | |
static NSString *cellId = @"Cell"; | |
cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellId]; | |
if (cell == nil) { | |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId] autorelease]; | |
} | |
UILabel *firstLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | |
firstLabel.textColor = [UIColor blackColor]; | |
firstLabel.backgroundColor = [UIColor clearColor]; | |
[cell.contentView addSubview:firstLabel]; | |
[firstLabel release]; | |
UILabel *lastLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | |
lastLabel.textColor = [UIColor blackColor]; | |
lastLabel.backgroundColor = [UIColor clearColor]; | |
[cell.contentView addSubview:lastLabel]; | |
[lastLabel release]; | |
UIFont *boldFont = [UIFont boldSystemFontOfSize:MIDDLE_FONT_HEIGHT]; | |
UIFont *font = [UIFont systemFontOfSize:MIDDLE_FONT_HEIGHT]; | |
if (contact.firstName.length > 0 && contact.lastName.length > 0) { | |
if (ABPersonGetSortOrdering() == kABPersonSortByFirstName) { | |
if (ABPersonGetCompositeNameFormat() == kABPersonCompositeNameFormatFirstNameFirst) { | |
CGSize size = [contact.firstName sizeWithFont:boldFont constrainedToSize:CGSizeMake(self.view.bounds.size.width, MAXFLOAT) lineBreakMode:UILineBreakModeTailTruncation]; | |
firstLabel.frame = CGRectMake(MIDDLE_GAP, 0.0, size.width, 60); | |
size = [contact.lastName sizeWithFont:font constrainedToSize:CGSizeMake(self.view.bounds.size.width - CGRectGetMaxX(firstLabel.frame) - MIDDLE_GAP, MAXFLOAT) lineBreakMode:UILineBreakModeTailTruncation]; | |
lastLabel.frame = CGRectMake(CGRectGetMaxX(firstLabel.frame)+MIDDLE_GAP, 0.0, size.width, 60); | |
firstLabel.font = boldFont; | |
lastLabel.font = font; | |
firstLabel.text = contact.firstName; | |
lastLabel.text = contact.lastName; | |
}else{ | |
CGSize size = [contact.lastName sizeWithFont:font constrainedToSize:CGSizeMake(self.view.bounds.size.width, MAXFLOAT) lineBreakMode:UILineBreakModeTailTruncation]; | |
firstLabel.frame = CGRectMake(MIDDLE_GAP, 0.0, size.width, 60); | |
size = [contact.firstName sizeWithFont:boldFont constrainedToSize:CGSizeMake(self.view.bounds.size.width - CGRectGetMaxX(firstLabel.frame) - MIDDLE_GAP, MAXFLOAT) lineBreakMode:UILineBreakModeTailTruncation]; | |
lastLabel.frame = CGRectMake(CGRectGetMaxX(firstLabel.frame)+MIDDLE_GAP, 0.0, size.width, 60); | |
firstLabel.font = font; | |
lastLabel.font = boldFont; | |
firstLabel.text = contact.lastName; | |
lastLabel.text = contact.firstName; | |
} | |
}else{ | |
if (ABPersonGetCompositeNameFormat() == kABPersonCompositeNameFormatFirstNameFirst) { | |
CGSize size = [contact.firstName sizeWithFont:font constrainedToSize:CGSizeMake(self.view.bounds.size.width, MAXFLOAT) lineBreakMode:UILineBreakModeTailTruncation]; | |
firstLabel.frame = CGRectMake(MIDDLE_GAP, 0.0, size.width, 60); | |
size = [contact.lastName sizeWithFont:boldFont constrainedToSize:CGSizeMake(self.view.bounds.size.width - CGRectGetMaxX(firstLabel.frame) - MIDDLE_GAP, MAXFLOAT) lineBreakMode:UILineBreakModeTailTruncation]; | |
lastLabel.frame = CGRectMake(CGRectGetMaxX(firstLabel.frame)+MIDDLE_GAP, 0.0, size.width, 60); | |
firstLabel.font = font; | |
lastLabel.font = boldFont; | |
firstLabel.text = contact.firstName; | |
lastLabel.text = contact.lastName; | |
}else{ | |
CGSize size = [contact.lastName sizeWithFont:boldFont constrainedToSize:CGSizeMake(self.view.bounds.size.width, MAXFLOAT) lineBreakMode:UILineBreakModeTailTruncation]; | |
firstLabel.frame = CGRectMake(MIDDLE_GAP, 0.0, size.width, 60); | |
size = [contact.firstName sizeWithFont:font constrainedToSize:CGSizeMake(self.view.bounds.size.width - CGRectGetMaxX(firstLabel.frame) - MIDDLE_GAP, MAXFLOAT) lineBreakMode:UILineBreakModeTailTruncation]; | |
lastLabel.frame = CGRectMake(CGRectGetMaxX(firstLabel.frame)+MIDDLE_GAP, 0.0, size.width, 60); | |
firstLabel.font = boldFont; | |
lastLabel.font = font; | |
firstLabel.text = contact.lastName; | |
lastLabel.text = contact.firstName; | |
} | |
} | |
}else{ | |
firstLabel.font = boldFont; | |
firstLabel.frame = CGRectMake(MIDDLE_GAP, 0.0, self.view.bounds.size.width - 2*MIDDLE_GAP, 60); | |
firstLabel.lineBreakMode = UILineBreakModeTailTruncation; | |
if (contact.firstName.length > 0) { | |
firstLabel.text = contact.firstName; | |
} | |
if (contact.lastName.length > 0) { | |
firstLabel.text = contact.lastName; | |
} | |
} | |
return cell; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment