Use AvatarImageView

Conistently apply avatar style

* contact picker
* conversation settings
* home view

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 68d500b8f4
commit b11f8affa7

@ -2,13 +2,13 @@
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// //
#import <UIKit/UIKit.h>
#import "TSThread.h" #import "TSThread.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@class Contact; @class Contact;
@class OWSContactsManager; @class OWSContactsManager;
@class AvatarImageView;
typedef enum : NSUInteger { kArchiveState = 0, kInboxState = 1 } CellState; typedef enum : NSUInteger { kArchiveState = 0, kInboxState = 1 } CellState;
@ -16,7 +16,7 @@ typedef enum : NSUInteger { kArchiveState = 0, kInboxState = 1 } CellState;
@property (nonatomic) IBOutlet UILabel *nameLabel; @property (nonatomic) IBOutlet UILabel *nameLabel;
@property (nonatomic) IBOutlet UILabel *snippetLabel; @property (nonatomic) IBOutlet UILabel *snippetLabel;
@property (nonatomic) IBOutlet UIImageView *contactPictureView; @property (nonatomic) IBOutlet AvatarImageView *contactPictureView;
@property (nonatomic) IBOutlet UILabel *timeLabel; @property (nonatomic) IBOutlet UILabel *timeLabel;
@property (nonatomic) IBOutlet UIView *contentContainerView; @property (nonatomic) IBOutlet UIView *contentContainerView;
@property (nonatomic) IBOutlet UIView *messageCounter; @property (nonatomic) IBOutlet UIView *messageCounter;

@ -120,7 +120,6 @@ NS_ASSUME_NONNULL_BEGIN
self.snippetLabel.attributedText = snippetText; self.snippetLabel.attributedText = snippetText;
self.timeLabel.attributedText = attributedDate; self.timeLabel.attributedText = attributedDate;
self.contactPictureView.image = nil; self.contactPictureView.image = nil;
[UIUtil applyRoundedBorderToImageView:_contactPictureView];
self.separatorInset = UIEdgeInsetsMake(0, _contactPictureView.frame.size.width * 1.5f, 0, 0); self.separatorInset = UIEdgeInsetsMake(0, _contactPictureView.frame.size.width * 1.5f, 0, 0);

@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="15G1217" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait"> <device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/> <adaptation id="fullscreen"/>
</device> </device>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/> <capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies> </dependencies>
@ -16,13 +15,13 @@
<rect key="frame" x="0.0" y="0.0" width="400" height="72"/> <rect key="frame" x="0.0" y="0.0" width="400" height="72"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" multipleTouchEnabled="YES" contentMode="center" tableViewCell="axX-Rb-kiK" id="BRG-hJ-lRa"> <tableViewCellContentView key="contentView" multipleTouchEnabled="YES" contentMode="center" tableViewCell="axX-Rb-kiK" id="BRG-hJ-lRa">
<rect key="frame" x="0.0" y="0.0" width="400" height="71"/> <rect key="frame" x="0.0" y="0.0" width="400" height="71.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxY="YES"/>
<subviews> <subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kq8-RD-txC" userLabel="Container View"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kq8-RD-txC" userLabel="Container View">
<rect key="frame" x="0.0" y="0.0" width="400" height="72"/> <rect key="frame" x="0.0" y="0.0" width="400" height="72"/>
<subviews> <subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="p9o-x6-nT5"> <imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="p9o-x6-nT5" customClass="AvatarImageView" customModule="Signal" customModuleProvider="target">
<rect key="frame" x="10" y="10" width="52" height="53"/> <rect key="frame" x="10" y="10" width="52" height="53"/>
<constraints> <constraints>
<constraint firstAttribute="width" constant="52" id="mb7-1o-58k"/> <constraint firstAttribute="width" constant="52" id="mb7-1o-58k"/>

@ -539,12 +539,8 @@ NS_ASSUME_NONNULL_BEGIN
UIImage *avatar = [OWSAvatarBuilder buildImageForThread:self.thread contactsManager:self.contactsManager]; UIImage *avatar = [OWSAvatarBuilder buildImageForThread:self.thread contactsManager:self.contactsManager];
OWSAssert(avatar); OWSAssert(avatar);
const CGFloat kAvatarSize = 68.f; const CGFloat kAvatarSize = 68.f;
UIImageView *avatarView = [[UIImageView alloc] initWithImage:avatar]; AvatarImageView *avatarView = [[AvatarImageView alloc] initWithImage:avatar];
_avatarView = avatarView; _avatarView = avatarView;
avatarView.layer.borderColor = UIColor.clearColor.CGColor;
avatarView.layer.masksToBounds = YES;
avatarView.layer.cornerRadius = kAvatarSize / 2.0f;
avatarView.contentMode = UIViewContentModeScaleAspectFill;
[threadInfoView addSubview:avatarView]; [threadInfoView addSubview:avatarView];
[avatarView autoVCenterInSuperview]; [avatarView autoVCenterInSuperview];
[avatarView autoPinEdgeToSuperviewEdge:ALEdgeLeft]; [avatarView autoPinEdgeToSuperviewEdge:ALEdgeLeft];

@ -1,14 +1,45 @@
// Created by Michael Kirk on 12/11/16. //
// Copyright © 2016 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
import UIKit import UIKit
@IBDesignable @IBDesignable
class AvatarImageView: UIImageView { class AvatarImageView: UIImageView {
override func layoutSubviews() { init() {
super.init(frame: CGRect.zero)
self.configureView()
}
override init(frame: CGRect) {
super.init(frame: frame)
self.configureView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.configureView()
}
override init(image: UIImage?) {
super.init(image: image)
self.configureView()
}
func configureView() {
self.layer.minificationFilter = kCAFilterTrilinear
self.layer.magnificationFilter = kCAFilterTrilinear
self.layer.borderWidth = 0.5
self.layer.masksToBounds = true self.layer.masksToBounds = true
self.layer.cornerRadius = self.frame.size.width / 2 if self.image == nil {
self.image = #imageLiteral(resourceName: "empty-group-avatar")
}
self.contentMode = .scaleToFill
} }
override func layoutSubviews() {
self.layer.borderColor = UIColor.black.cgColor.copy(alpha: 0.15)
self.layer.cornerRadius = self.frame.size.width / 2
}
} }

@ -6,6 +6,7 @@
#import "Environment.h" #import "Environment.h"
#import "OWSContactAvatarBuilder.h" #import "OWSContactAvatarBuilder.h"
#import "OWSContactsManager.h" #import "OWSContactsManager.h"
#import "Signal-Swift.h"
#import "UIFont+OWS.h" #import "UIFont+OWS.h"
#import "UIUtil.h" #import "UIUtil.h"
#import "UIView+OWS.h" #import "UIView+OWS.h"
@ -52,14 +53,7 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI
- (void)configureProgrammatically - (void)configureProgrammatically
{ {
const CGFloat kAvatarSize = 40.f; const CGFloat kAvatarSize = 40.f;
_avatarView = [UIImageView new]; _avatarView = [AvatarImageView new];
_avatarView.image = [UIImage imageNamed:@"empty-group-avatar"];
_avatarView.contentMode = UIViewContentModeScaleToFill;
// applyRoundedBorderToImageView requires the avatar to have
// the correct size.
_avatarView.frame = CGRectMake(0, 0, kAvatarSize, kAvatarSize);
_avatarView.layer.minificationFilter = kCAFilterTrilinear;
_avatarView.layer.magnificationFilter = kCAFilterTrilinear;
[self.contentView addSubview:_avatarView]; [self.contentView addSubview:_avatarView];
_nameLabel = [UILabel new]; _nameLabel = [UILabel new];
@ -147,12 +141,6 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI
[self layoutSubviews]; [self layoutSubviews];
} }
- (void)layoutSubviews
{
[super layoutSubviews];
[UIUtil applyRoundedBorderToImageView:self.avatarView];
}
- (void)prepareForReuse - (void)prepareForReuse
{ {
self.accessoryMessage = nil; self.accessoryMessage = nil;

Loading…
Cancel
Save