You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/Signal/src/views/ContactTableViewCell.m

66 lines
2.6 KiB
Matlab

11 years ago
#import "ContactTableViewCell.h"
#import "UIUtil.h"
11 years ago
#import "Environment.h"
#import "PhoneManager.h"
@interface ContactTableViewCell ()
11 years ago
@property (strong, nonatomic) Contact *associatedContact;
@end
11 years ago
@implementation ContactTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
11 years ago
return self;
}
- (NSString *)reuseIdentifier {
return NSStringFromClass(self.class);
11 years ago
}
- (void)configureWithContact:(Contact *)contact {
self.associatedContact = contact;
self.nameLabel.attributedText = [self attributedStringForContact:contact];
11 years ago
}
- (NSAttributedString *)attributedStringForContact:(Contact *)contact {
NSMutableAttributedString *fullNameAttributedString =
[[NSMutableAttributedString alloc] initWithString:contact.fullName];
11 years ago
UIFont *firstNameFont;
UIFont *lastNameFont;
11 years ago
if (ABPersonGetSortOrdering() == kABPersonCompositeNameFormatFirstNameFirst) {
firstNameFont = [UIFont ows_mediumFontWithSize:_nameLabel.font.pointSize];
lastNameFont = [UIFont ows_regularFontWithSize:_nameLabel.font.pointSize];
} else {
firstNameFont = [UIFont ows_regularFontWithSize:_nameLabel.font.pointSize];
lastNameFont = [UIFont ows_mediumFontWithSize:_nameLabel.font.pointSize];
11 years ago
}
[fullNameAttributedString addAttribute:NSFontAttributeName
value:firstNameFont
range:NSMakeRange(0, contact.firstName.length)];
[fullNameAttributedString addAttribute:NSFontAttributeName
value:lastNameFont
range:NSMakeRange(contact.firstName.length + 1, contact.lastName.length)];
[fullNameAttributedString addAttribute:NSForegroundColorAttributeName
value:[UIColor blackColor]
range:NSMakeRange(0, contact.fullName.length)];
if (ABPersonGetSortOrdering() == kABPersonCompositeNameFormatFirstNameFirst) {
[fullNameAttributedString addAttribute:NSForegroundColorAttributeName
value:[UIColor ows_darkGrayColor]
range:NSMakeRange(contact.firstName.length + 1, contact.lastName.length)];
} else {
[fullNameAttributedString addAttribute:NSForegroundColorAttributeName
value:[UIColor ows_darkGrayColor]
range:NSMakeRange(0, contact.firstName.length)];
}
11 years ago
return fullNameAttributedString;
}
@end