IGListKit/Examples/Examples-iOS/IGListKitExamples/Views/PersonCell.m
Tim Oliver a1b9c2ddb3 Updated corporate branding in IGListKit source files
Summary:
A quick push to fix something I noticed while studying how IGListKit works. This simply replaces "Facebook, Inc" with "Meta Platforms, Inc" in all of the source files where the company copyright notice is posted. This should help bring our external facing projects more in line with our new corporate branding.

There's still a lot more references to "Facebook" as a company in the library (especially around linking to other Meta sponsored open source libraries), but this might need additional scrutiny and review on a case-by-case basis, so let's handle those ones separately.

Reviewed By: lorixx

Differential Revision: D41207363

fbshipit-source-id: 57cdbf5eb1023b41a5f32c0c05e01628686a19fe
2022-11-15 21:47:29 -08:00

100 lines
3.8 KiB
Objective-C

/*
* Copyright (c) Meta Platforms, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "PersonCell.h"
#import "PersonModel.h"
@interface PersonCell ()
@property (nonatomic, strong) UIView *avatarView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIView *separatorView;
@property (nonatomic, assign) CGFloat separatorHeight;
@end
@implementation PersonCell
- (instancetype)init {
if (self = [super init]) {
[self setupSubviews];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self setupSubviews];
}
return self;
}
- (void)setupSubviews {
self.avatarView = [[UIView alloc] init];
self.avatarView.backgroundColor = [UIColor colorWithWhite:0.85 alpha:1.0];
[self.contentView addSubview:self.avatarView];
self.nameLabel = [[UILabel alloc] init];
self.nameLabel.textAlignment = NSTextAlignmentLeft;
[self.contentView addSubview:self.nameLabel];
self.separatorView = [[UIView alloc] init];
[self.contentView addSubview:self.separatorView];
if (@available(iOS 13.0, *)) {
self.nameLabel.textColor = [UIColor labelColor];
self.separatorView.backgroundColor = [UIColor separatorColor];
} else {
self.nameLabel.textColor = [UIColor darkTextColor];
self.separatorView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:1.0];
}
self.separatorHeight = (1 / [UIScreen mainScreen].scale);
}
- (void)layoutSubviews {
[super layoutSubviews];
const CGFloat outerInset = 10;
const CGRect bounds = self.contentView.bounds;
const CGRect insetBounds = CGRectInset(bounds, outerInset, outerInset);
const CGFloat avatarViewWidth = insetBounds.size.height;
const CGRect avatarViewFrame = CGRectMake(outerInset, outerInset, avatarViewWidth, avatarViewWidth);
if (!CGRectEqualToRect(avatarViewFrame, self.avatarView.frame)) {
self.avatarView.layer.cornerRadius = round(avatarViewWidth / 2.0);
self.avatarView.layer.masksToBounds = YES;
self.avatarView.frame = avatarViewFrame;
}
const CGFloat avatarLabelInset = 8;
self.nameLabel.frame = CGRectMake(CGRectGetMaxX(avatarViewFrame) + avatarLabelInset,
outerInset,
CGRectGetWidth(insetBounds) - avatarViewWidth - avatarLabelInset * 2,
CGRectGetHeight(insetBounds));
self.separatorView.frame = CGRectMake(0,
CGRectGetHeight(bounds) - self.separatorHeight,
CGRectGetWidth(bounds),
self.separatorHeight);
}
static NSAttributedString *AttributedStringForPerson(PersonModel *person) {
NSMutableAttributedString *string = [NSMutableAttributedString new];
[string appendAttributedString:[[NSAttributedString alloc] initWithString:person.firstName
attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:15.0]}]];
[string appendAttributedString:[[NSAttributedString alloc] initWithString:@" "
attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:15.0]}]];
[string appendAttributedString:[[NSAttributedString alloc] initWithString:person.lastName
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.0]}]];
return string;
}
- (void)setPerson:(PersonModel *)person {
_person = [person copy];
self.nameLabel.attributedText = AttributedStringForPerson(person);
}
@end