mirror of https://github.com/oxen-io/session-ios
Merge branch 'charlesmchen/converationColorsVsAvatars'
commit
7ab76551c3
@ -1,20 +0,0 @@
|
|||||||
|
|
||||||
MIT License
|
|
||||||
Copyright (c) 2013-present Jesse Squires
|
|
||||||
|
|
||||||
http://www.jessesquires.com
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
||||||
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
||||||
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
||||||
following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
||||||
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
||||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
||||||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -1,104 +0,0 @@
|
|||||||

|
|
||||||
|
|
||||||
[](https://travis-ci.org/jessesquires/JSQMessagesViewController) [][podLink] [][mitLink] [](https://codecov.io/gh/jessesquires/JSQMessagesViewController) [][docsLink]
|
|
||||||
|
|
||||||
![Screenshot0][img0] ![Screenshot1][img1]
|
|
||||||
|
|
||||||
![Screenshot2][img2] ![Screenshot3][img3]
|
|
||||||
|
|
||||||
> More screenshots available at [CocoaControls](https://www.cocoacontrols.com/controls/jsqmessagesviewcontroller)
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
See the [website](http://www.jessesquires.com/JSQMessagesViewController/) for the list of features.
|
|
||||||
|
|
||||||
## Design Goals
|
|
||||||
|
|
||||||
- Closely mimic the [iOS Messages](http://www.apple.com/ios/messages/) style and behavior
|
|
||||||
- [SOLID](https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)) design
|
|
||||||
- Easy customization and extension for clients
|
|
||||||
|
|
||||||
## Dependencies
|
|
||||||
|
|
||||||
* [JSQSystemSoundPlayer][playerLink]
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
* iOS 7.0+
|
|
||||||
* ARC
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
### [CocoaPods](https://cocoapods.org/) (recommended)
|
|
||||||
|
|
||||||
````ruby
|
|
||||||
# For latest release in cocoapods
|
|
||||||
pod 'JSQMessagesViewController'
|
|
||||||
|
|
||||||
# Latest on develop
|
|
||||||
pod 'JSQMessagesViewController', :git => 'https://github.com/jessesquires/JSQMessagesViewController.git', :branch => 'develop'
|
|
||||||
|
|
||||||
# For version 5.3.2
|
|
||||||
pod 'JSQMessagesViewController', :git => 'https://github.com/jessesquires/JSQMessagesViewController', :branch => 'version_5.3.2_patch'
|
|
||||||
````
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
See the [Getting Started](https://github.com/jessesquires/JSQMessagesViewController/blob/develop/Documentation/getting_started.md) guide!
|
|
||||||
|
|
||||||
## Questions & Help
|
|
||||||
|
|
||||||
* Review the [FAQ](https://github.com/jessesquires/JSQMessagesViewController/blob/develop/Documentation/faq.md).
|
|
||||||
* Search issues for previous and current [questions](https://github.com/jessesquires/JSQMessagesViewController/issues?utf8=✓&q=label%3A%22questions+%26+help%22+). *Do not open duplicates.*
|
|
||||||
* [StackOverflow](http://stackoverflow.com/questions/tagged/jsqmessagesviewcontroller) is often the most appropriate place for questions and help. We have our own tag, `jsqmessagesviewcontroller`.
|
|
||||||
* See the [Migration Guide](https://github.com/jessesquires/JSQMessagesViewController/blob/develop/Documentation/migration.md) for migrating between major versions of the library.
|
|
||||||
* **Only ask questions that are _specific_ to this library.**
|
|
||||||
* **Please avoid emailing questions.** I prefer to keep questions and their answers open-source.
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
Read the docs, [available here][docsLink] via [@CocoaDocs](https://twitter.com/CocoaDocs).
|
|
||||||
|
|
||||||
## Core team
|
|
||||||
|
|
||||||
- Jesse Squires ([**@jesse_squires**](https://twitter.com/jesse_squires))
|
|
||||||
- Harlan Haskans ([**@harlanhaskins**](https://github.com/harlanhaskins))
|
|
||||||
- Eli Burke ([**@eliburke**](https://github.com/eliburke))
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
Please follow these sweet [contribution guidelines](https://github.com/jessesquires/JSQMessagesViewController/blob/develop/.github/CONTRIBUTING.md).
|
|
||||||
|
|
||||||
> **Interested in becoming a core contributor with push access? See our [onboarding guide](https://github.com/jessesquires/JSQMessagesViewController/blob/develop/Documentation/contributor_onboarding.md) for details.**
|
|
||||||
|
|
||||||
## Donate
|
|
||||||
|
|
||||||
Support the development of this **free** library! **[Donate](https://cash.me/$jsq)** via [Square Cash](https://cash.me/).
|
|
||||||
|
|
||||||
## Credits
|
|
||||||
|
|
||||||
* Created and maintained by [**@jesse_squires**](https://twitter.com/jesse_squires).
|
|
||||||
* Many thanks to [**the contributors**](https://github.com/jessesquires/JSQMessagesViewController/graphs/contributors) of this project.
|
|
||||||
* iOS assets extracted using [**@0xced**](https://github.com/0xced) / [iOS-Artwork-Extractor](https://github.com/0xced/iOS-Artwork-Extractor).
|
|
||||||
|
|
||||||
## Apps using this library
|
|
||||||
|
|
||||||
According to [CocoaPods stats](https://cocoapods.org/pods/JSQMessagesViewController), over **9,000 apps** are using `JSQMessagesViewController`. [Here are the ones](https://github.com/jessesquires/JSQMessagesViewController/blob/develop/Documentation/apps_using_this_library.md) that we know about. Please submit a [pull request](https://github.com/jessesquires/JSQMessagesViewController/compare) to add your app! :smile:
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
`JSQMessagesViewController` is released under an [MIT License][mitLink]. See `LICENSE` for details.
|
|
||||||
|
|
||||||
>**Copyright © 2013-present Jesse Squires.**
|
|
||||||
|
|
||||||
*Please provide attribution, it is greatly appreciated.*
|
|
||||||
|
|
||||||
[docsLink]:http://cocoadocs.org/docsets/JSQMessagesViewController/
|
|
||||||
[podLink]:https://cocoapods.org/pods/JSQMessagesViewController
|
|
||||||
[mitLink]:http://opensource.org/licenses/MIT
|
|
||||||
[playerLink]:https://github.com/jessesquires/JSQSystemSoundPlayer
|
|
||||||
|
|
||||||
[img0]:https://raw.githubusercontent.com/jessesquires/JSQMessagesViewController/develop/Screenshots/screenshot0.png
|
|
||||||
[img1]:https://raw.githubusercontent.com/jessesquires/JSQMessagesViewController/develop/Screenshots/screenshot1.png
|
|
||||||
[img2]:https://raw.githubusercontent.com/jessesquires/JSQMessagesViewController/develop/Screenshots/screenshot2.png
|
|
||||||
[img3]:https://raw.githubusercontent.com/jessesquires/JSQMessagesViewController/develop/Screenshots/screenshot3.png
|
|
@ -1,7 +0,0 @@
|
|||||||
The files in this directory are drawn from JSQMessagesViewController, created by Jesse Squires. These files have been pulled into the Signal-iOS repository with his permission.
|
|
||||||
|
|
||||||
https://github.com/jessesquires/JSQMessagesViewController
|
|
||||||
|
|
||||||
These files are available under the MIT License. See JSQMVC-LICENSE.
|
|
||||||
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Jesse Squires
|
|
||||||
// http://www.jessesquires.com
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Documentation
|
|
||||||
// http://cocoadocs.org/docsets/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// GitHub
|
|
||||||
// https://github.com/jessesquires/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License
|
|
||||||
// Copyright (c) 2014 Jesse Squires
|
|
||||||
// Released under an MIT license: http://opensource.org/licenses/MIT
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The `JSQMessageAvatarImageDataSource` protocol defines the common interface through which
|
|
||||||
* a `JSQMessagesViewController` and `JSQMessagesCollectionView` interact with avatar image model objects.
|
|
||||||
*
|
|
||||||
* It declares the required and optional methods that a class must implement so that instances
|
|
||||||
* of that class can be display properly within a `JSQMessagesCollectionViewCell`.
|
|
||||||
*
|
|
||||||
* A concrete class that conforms to this protocol is provided in the library. See `JSQMessagesAvatarImage`.
|
|
||||||
*
|
|
||||||
* @see JSQMessagesAvatarImage.
|
|
||||||
*/
|
|
||||||
@protocol JSQMessageAvatarImageDataSource <NSObject>
|
|
||||||
|
|
||||||
@required
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The avatar image for a regular display state.
|
|
||||||
*
|
|
||||||
* @discussion You may return `nil` from this method while the image is being downloaded.
|
|
||||||
*/
|
|
||||||
- (UIImage *)avatarImage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The avatar image for a highlighted display state.
|
|
||||||
*
|
|
||||||
* @discussion You may return `nil` from this method if this does not apply.
|
|
||||||
*/
|
|
||||||
- (UIImage *)avatarHighlightedImage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return A placeholder avatar image to be displayed if avatarImage is not yet available, or `nil`.
|
|
||||||
* For example, if avatarImage needs to be downloaded, this placeholder image
|
|
||||||
* will be used until avatarImage is not `nil`.
|
|
||||||
*
|
|
||||||
* @discussion If you do not need support for a placeholder image, that is, your images
|
|
||||||
* are stored locally on the device, then you may simply return the same value as avatarImage here.
|
|
||||||
*
|
|
||||||
* @warning You must not return `nil` from this method.
|
|
||||||
*/
|
|
||||||
- (UIImage *)avatarPlaceholderImage;
|
|
||||||
|
|
||||||
@end
|
|
@ -1,86 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Jesse Squires
|
|
||||||
// http://www.jessesquires.com
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Documentation
|
|
||||||
// http://cocoadocs.org/docsets/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// GitHub
|
|
||||||
// https://github.com/jessesquires/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License
|
|
||||||
// Copyright (c) 2014 Jesse Squires
|
|
||||||
// Released under an MIT license: http://opensource.org/licenses/MIT
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
#import "JSQMessageAvatarImageDataSource.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A `JSQMessagesAvatarImage` model object represents an avatar image.
|
|
||||||
* This is a concrete class that implements the `JSQMessageAvatarImageDataSource` protocol.
|
|
||||||
* It contains a regular avatar image, a highlighted avatar image, and a placeholder avatar image.
|
|
||||||
*
|
|
||||||
* @see JSQMessagesAvatarImageFactory.
|
|
||||||
*/
|
|
||||||
@interface JSQMessagesAvatarImage : NSObject <JSQMessageAvatarImageDataSource, NSCopying>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The avatar image for a regular display state.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, strong) UIImage *avatarImage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The avatar image for a highlighted display state.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, strong) UIImage *avatarHighlightedImage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the placeholder image for an avatar to display if avatarImage is `nil`.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, strong, readonly) UIImage *avatarPlaceholderImage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes and returns an avatar image object having the specified image.
|
|
||||||
*
|
|
||||||
* @param image The image for this avatar image. This image will be used for the all of the following
|
|
||||||
* properties: avatarImage, avatarHighlightedImage, avatarPlaceholderImage;
|
|
||||||
* This value must not be `nil`.
|
|
||||||
*
|
|
||||||
* @return An initialized `JSQMessagesAvatarImage` object if successful, `nil` otherwise.
|
|
||||||
*/
|
|
||||||
+ (instancetype)avatarWithImage:(UIImage *)image;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes and returns an avatar image object having the specified placeholder image.
|
|
||||||
*
|
|
||||||
* @param placeholderImage The placeholder image for this avatar image. This value must not be `nil`.
|
|
||||||
*
|
|
||||||
* @return An initialized `JSQMessagesAvatarImage` object if successful, `nil` otherwise.
|
|
||||||
*/
|
|
||||||
+ (instancetype)avatarImageWithPlaceholder:(UIImage *)placeholderImage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes and returns an avatar image object having the specified regular, highlighed, and placeholder images.
|
|
||||||
*
|
|
||||||
* @param avatarImage The avatar image for a regular display state.
|
|
||||||
* @param highlightedImage The avatar image for a highlighted display state.
|
|
||||||
* @param placeholderImage The placeholder image for this avatar image. This value must not be `nil`.
|
|
||||||
*
|
|
||||||
* @return An initialized `JSQMessagesAvatarImage` object if successful, `nil` otherwise.
|
|
||||||
*/
|
|
||||||
- (instancetype)initWithAvatarImage:(UIImage *)avatarImage
|
|
||||||
highlightedImage:(UIImage *)highlightedImage
|
|
||||||
placeholderImage:(UIImage *)placeholderImage NS_DESIGNATED_INITIALIZER;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Not a valid initializer.
|
|
||||||
*/
|
|
||||||
- (id)init NS_UNAVAILABLE;
|
|
||||||
|
|
||||||
@end
|
|
@ -1,78 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Jesse Squires
|
|
||||||
// http://www.jessesquires.com
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Documentation
|
|
||||||
// http://cocoadocs.org/docsets/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// GitHub
|
|
||||||
// https://github.com/jessesquires/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License
|
|
||||||
// Copyright (c) 2014 Jesse Squires
|
|
||||||
// Released under an MIT license: http://opensource.org/licenses/MIT
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "JSQMessagesAvatarImage.h"
|
|
||||||
|
|
||||||
@implementation JSQMessagesAvatarImage
|
|
||||||
|
|
||||||
#pragma mark - Initialization
|
|
||||||
|
|
||||||
+ (instancetype)avatarWithImage:(UIImage *)image
|
|
||||||
{
|
|
||||||
NSParameterAssert(image != nil);
|
|
||||||
|
|
||||||
return [[JSQMessagesAvatarImage alloc] initWithAvatarImage:image
|
|
||||||
highlightedImage:image
|
|
||||||
placeholderImage:image];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (instancetype)avatarImageWithPlaceholder:(UIImage *)placeholderImage
|
|
||||||
{
|
|
||||||
return [[JSQMessagesAvatarImage alloc] initWithAvatarImage:nil
|
|
||||||
highlightedImage:nil
|
|
||||||
placeholderImage:placeholderImage];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithAvatarImage:(UIImage *)avatarImage
|
|
||||||
highlightedImage:(UIImage *)highlightedImage
|
|
||||||
placeholderImage:(UIImage *)placeholderImage
|
|
||||||
{
|
|
||||||
NSParameterAssert(placeholderImage != nil);
|
|
||||||
|
|
||||||
self = [super init];
|
|
||||||
if (self) {
|
|
||||||
_avatarImage = avatarImage;
|
|
||||||
_avatarHighlightedImage = highlightedImage;
|
|
||||||
_avatarPlaceholderImage = placeholderImage;
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - NSObject
|
|
||||||
|
|
||||||
- (NSString *)description
|
|
||||||
{
|
|
||||||
return [NSString stringWithFormat:@"<%@: avatarImage=%@, avatarHighlightedImage=%@, avatarPlaceholderImage=%@>",
|
|
||||||
[self class], self.avatarImage, self.avatarHighlightedImage, self.avatarPlaceholderImage];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id)debugQuickLookObject
|
|
||||||
{
|
|
||||||
return [[UIImageView alloc] initWithImage:self.avatarImage ?: self.avatarPlaceholderImage];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - NSCopying
|
|
||||||
|
|
||||||
- (instancetype)copyWithZone:(NSZone *)zone
|
|
||||||
{
|
|
||||||
return [[[self class] allocWithZone:zone] initWithAvatarImage:[UIImage imageWithCGImage:self.avatarImage.CGImage]
|
|
||||||
highlightedImage:[UIImage imageWithCGImage:self.avatarHighlightedImage.CGImage]
|
|
||||||
placeholderImage:[UIImage imageWithCGImage:self.avatarPlaceholderImage.CGImage]];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
@ -1,99 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Jesse Squires
|
|
||||||
// http://www.jessesquires.com
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Documentation
|
|
||||||
// http://cocoadocs.org/docsets/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// GitHub
|
|
||||||
// https://github.com/jessesquires/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License
|
|
||||||
// Copyright (c) 2014 Jesse Squires
|
|
||||||
// Released under an MIT license: http://opensource.org/licenses/MIT
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
#import "JSQMessagesAvatarImage.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* `JSQMessagesAvatarImageFactory` is a factory that provides a means for creating and styling
|
|
||||||
* `JSQMessagesAvatarImage` objects to be displayed in a `JSQMessagesCollectionViewCell` of a `JSQMessagesCollectionView`.
|
|
||||||
*/
|
|
||||||
@interface JSQMessagesAvatarImageFactory : NSObject
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and returns a `JSQMessagesAvatarImage` object with the specified placeholderImage that is
|
|
||||||
* cropped to a circle of the given diameter.
|
|
||||||
*
|
|
||||||
* @param placeholderImage An image object that represents a placeholder avatar image. This value must not be `nil`.
|
|
||||||
* @param diameter An integer value specifying the diameter size of the avatar in points. This value must be greater than `0`.
|
|
||||||
*
|
|
||||||
* @return An initialized `JSQMessagesAvatarImage` object if created successfully, `nil` otherwise.
|
|
||||||
*/
|
|
||||||
+ (JSQMessagesAvatarImage *)avatarImageWithPlaceholder:(UIImage *)placeholderImage diameter:(NSUInteger)diameter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and returns a `JSQMessagesAvatarImage` object with the specified image that is
|
|
||||||
* cropped to a circle of the given diameter and used for the `avatarImage` and `avatarPlaceholderImage` properties
|
|
||||||
* of the returned `JSQMessagesAvatarImage` object. This image is then copied and has a transparent black mask applied to it,
|
|
||||||
* which is used for the `avatarHighlightedImage` property of the returned `JSQMessagesAvatarImage` object.
|
|
||||||
*
|
|
||||||
* @param image An image object that represents an avatar image. This value must not be `nil`.
|
|
||||||
* @param diameter An integer value specifying the diameter size of the avatar in points. This value must be greater than `0`.
|
|
||||||
*
|
|
||||||
* @return An initialized `JSQMessagesAvatarImage` object if created successfully, `nil` otherwise.
|
|
||||||
*/
|
|
||||||
+ (JSQMessagesAvatarImage *)avatarImageWithImage:(UIImage *)image diameter:(NSUInteger)diameter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a copy of the specified image that is cropped to a circle with the given diameter.
|
|
||||||
*
|
|
||||||
* @param image The image to crop. This value must not be `nil`.
|
|
||||||
* @param diameter An integer value specifying the diameter size of the image in points. This value must be greater than `0`.
|
|
||||||
*
|
|
||||||
* @return A new image object if successful, `nil` otherwise.
|
|
||||||
*/
|
|
||||||
+ (UIImage *)circularAvatarImage:(UIImage *)image withDiameter:(NSUInteger)diameter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a copy of the specified image that is cropped to a circle with the given diameter.
|
|
||||||
* Additionally, a transparent overlay is applied to the image to represent a pressed or highlighted state.
|
|
||||||
*
|
|
||||||
* @param image The image to crop. This value must not be `nil`.
|
|
||||||
* @param diameter An integer value specifying the diameter size of the image in points. This value must be greater than `0`.
|
|
||||||
*
|
|
||||||
* @return A new image object if successful, `nil` otherwise.
|
|
||||||
*/
|
|
||||||
+ (UIImage *)circularAvatarHighlightedImage:(UIImage *)image withDiameter:(NSUInteger)diameter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and returns a `JSQMessagesAvatarImage` object with a circular shape that displays the specified userInitials
|
|
||||||
* with the given backgroundColor, textColor, font, and diameter.
|
|
||||||
*
|
|
||||||
* @param userInitials The user initials to display in the avatar image. This value must not be `nil`.
|
|
||||||
* @param backgroundColor The background color of the avatar. This value must not be `nil`.
|
|
||||||
* @param textColor The color of the text of the userInitials. This value must not be `nil`.
|
|
||||||
* @param font The font applied to userInitials. This value must not be `nil`.
|
|
||||||
* @param diameter The diameter of the avatar image. This value must be greater than `0`.
|
|
||||||
*
|
|
||||||
* @return An initialized `JSQMessagesAvatarImage` object if created successfully, `nil` otherwise.
|
|
||||||
*
|
|
||||||
* @discussion This method does not attempt to detect or correct incompatible parameters.
|
|
||||||
* That is to say, you are responsible for providing a font size and diameter that make sense.
|
|
||||||
* For example, a font size of `14.0f` and a diameter of `34.0f` will result in an avatar similar to Messages in iOS 7.
|
|
||||||
* However, a font size `30.0f` and diameter of `10.0f` will not produce a desirable image.
|
|
||||||
* Further, this method does not check the length of userInitials. It is recommended that you pass a string of length `2` or `3`.
|
|
||||||
*/
|
|
||||||
+ (JSQMessagesAvatarImage *)avatarImageWithUserInitials:(NSString *)userInitials
|
|
||||||
backgroundColor:(UIColor *)backgroundColor
|
|
||||||
textColor:(UIColor *)textColor
|
|
||||||
font:(UIFont *)font
|
|
||||||
diameter:(NSUInteger)diameter;
|
|
||||||
|
|
||||||
@end
|
|
@ -1,159 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Jesse Squires
|
|
||||||
// http://www.jessesquires.com
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Documentation
|
|
||||||
// http://cocoadocs.org/docsets/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// GitHub
|
|
||||||
// https://github.com/jessesquires/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License
|
|
||||||
// Copyright (c) 2014 Jesse Squires
|
|
||||||
// Released under an MIT license: http://opensource.org/licenses/MIT
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "JSQMessagesAvatarImageFactory.h"
|
|
||||||
|
|
||||||
#import "UIColor+JSQMessages.h"
|
|
||||||
|
|
||||||
|
|
||||||
@implementation JSQMessagesAvatarImageFactory
|
|
||||||
|
|
||||||
#pragma mark - Public
|
|
||||||
|
|
||||||
+ (JSQMessagesAvatarImage *)avatarImageWithPlaceholder:(UIImage *)placeholderImage diameter:(NSUInteger)diameter
|
|
||||||
{
|
|
||||||
UIImage *circlePlaceholderImage = [JSQMessagesAvatarImageFactory jsq_circularImage:placeholderImage
|
|
||||||
withDiameter:diameter
|
|
||||||
highlightedColor:nil];
|
|
||||||
|
|
||||||
return [JSQMessagesAvatarImage avatarImageWithPlaceholder:circlePlaceholderImage];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (JSQMessagesAvatarImage *)avatarImageWithImage:(UIImage *)image diameter:(NSUInteger)diameter
|
|
||||||
{
|
|
||||||
UIImage *avatar = [JSQMessagesAvatarImageFactory circularAvatarImage:image withDiameter:diameter];
|
|
||||||
UIImage *highlightedAvatar = [JSQMessagesAvatarImageFactory circularAvatarHighlightedImage:image withDiameter:diameter];
|
|
||||||
|
|
||||||
return [[JSQMessagesAvatarImage alloc] initWithAvatarImage:avatar
|
|
||||||
highlightedImage:highlightedAvatar
|
|
||||||
placeholderImage:avatar];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (UIImage *)circularAvatarImage:(UIImage *)image withDiameter:(NSUInteger)diameter
|
|
||||||
{
|
|
||||||
return [JSQMessagesAvatarImageFactory jsq_circularImage:image
|
|
||||||
withDiameter:diameter
|
|
||||||
highlightedColor:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (UIImage *)circularAvatarHighlightedImage:(UIImage *)image withDiameter:(NSUInteger)diameter
|
|
||||||
{
|
|
||||||
return [JSQMessagesAvatarImageFactory jsq_circularImage:image
|
|
||||||
withDiameter:diameter
|
|
||||||
highlightedColor:[UIColor colorWithWhite:0.1f alpha:0.3f]];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (JSQMessagesAvatarImage *)avatarImageWithUserInitials:(NSString *)userInitials
|
|
||||||
backgroundColor:(UIColor *)backgroundColor
|
|
||||||
textColor:(UIColor *)textColor
|
|
||||||
font:(UIFont *)font
|
|
||||||
diameter:(NSUInteger)diameter
|
|
||||||
{
|
|
||||||
UIImage *avatarImage = [JSQMessagesAvatarImageFactory jsq_imageWitInitials:userInitials
|
|
||||||
backgroundColor:backgroundColor
|
|
||||||
textColor:textColor
|
|
||||||
font:font
|
|
||||||
diameter:diameter];
|
|
||||||
|
|
||||||
UIImage *avatarHighlightedImage = [JSQMessagesAvatarImageFactory jsq_circularImage:avatarImage
|
|
||||||
withDiameter:diameter
|
|
||||||
highlightedColor:[UIColor colorWithWhite:0.1f alpha:0.3f]];
|
|
||||||
|
|
||||||
return [[JSQMessagesAvatarImage alloc] initWithAvatarImage:avatarImage
|
|
||||||
highlightedImage:avatarHighlightedImage
|
|
||||||
placeholderImage:avatarImage];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Private
|
|
||||||
|
|
||||||
+ (UIImage *)jsq_imageWitInitials:(NSString *)initials
|
|
||||||
backgroundColor:(UIColor *)backgroundColor
|
|
||||||
textColor:(UIColor *)textColor
|
|
||||||
font:(UIFont *)font
|
|
||||||
diameter:(NSUInteger)diameter
|
|
||||||
{
|
|
||||||
NSParameterAssert(initials != nil);
|
|
||||||
NSParameterAssert(backgroundColor != nil);
|
|
||||||
NSParameterAssert(textColor != nil);
|
|
||||||
NSParameterAssert(font != nil);
|
|
||||||
NSParameterAssert(diameter > 0);
|
|
||||||
|
|
||||||
CGRect frame = CGRectMake(0.0f, 0.0f, diameter, diameter);
|
|
||||||
|
|
||||||
NSDictionary *attributes = @{ NSFontAttributeName : font,
|
|
||||||
NSForegroundColorAttributeName : textColor };
|
|
||||||
|
|
||||||
CGRect textFrame = [initials boundingRectWithSize:frame.size
|
|
||||||
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
|
|
||||||
attributes:attributes
|
|
||||||
context:nil];
|
|
||||||
|
|
||||||
CGPoint frameMidPoint = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame));
|
|
||||||
CGPoint textFrameMidPoint = CGPointMake(CGRectGetMidX(textFrame), CGRectGetMidY(textFrame));
|
|
||||||
|
|
||||||
CGFloat dx = frameMidPoint.x - textFrameMidPoint.x;
|
|
||||||
CGFloat dy = frameMidPoint.y - textFrameMidPoint.y;
|
|
||||||
CGPoint drawPoint = CGPointMake(dx, dy);
|
|
||||||
UIImage *image = nil;
|
|
||||||
|
|
||||||
UIGraphicsBeginImageContextWithOptions(frame.size, NO, [UIScreen mainScreen].scale);
|
|
||||||
{
|
|
||||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
||||||
|
|
||||||
CGContextSetFillColorWithColor(context, backgroundColor.CGColor);
|
|
||||||
CGContextFillRect(context, frame);
|
|
||||||
[initials drawAtPoint:drawPoint withAttributes:attributes];
|
|
||||||
|
|
||||||
image = UIGraphicsGetImageFromCurrentImageContext();
|
|
||||||
|
|
||||||
}
|
|
||||||
UIGraphicsEndImageContext();
|
|
||||||
|
|
||||||
return [JSQMessagesAvatarImageFactory jsq_circularImage:image withDiameter:diameter highlightedColor:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (UIImage *)jsq_circularImage:(UIImage *)image withDiameter:(NSUInteger)diameter highlightedColor:(UIColor *)highlightedColor
|
|
||||||
{
|
|
||||||
NSParameterAssert(image != nil);
|
|
||||||
NSParameterAssert(diameter > 0);
|
|
||||||
|
|
||||||
CGRect frame = CGRectMake(0.0f, 0.0f, diameter, diameter);
|
|
||||||
UIImage *newImage = nil;
|
|
||||||
|
|
||||||
UIGraphicsBeginImageContextWithOptions(frame.size, NO, [UIScreen mainScreen].scale);
|
|
||||||
{
|
|
||||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
||||||
|
|
||||||
UIBezierPath *imgPath = [UIBezierPath bezierPathWithOvalInRect:frame];
|
|
||||||
[imgPath addClip];
|
|
||||||
[image drawInRect:frame];
|
|
||||||
|
|
||||||
if (highlightedColor != nil) {
|
|
||||||
CGContextSetFillColorWithColor(context, highlightedColor.CGColor);
|
|
||||||
CGContextFillEllipseInRect(context, frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
||||||
|
|
||||||
}
|
|
||||||
UIGraphicsEndImageContext();
|
|
||||||
|
|
||||||
return newImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
@ -1,56 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Jesse Squires
|
|
||||||
// http://www.jessesquires.com
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Documentation
|
|
||||||
// http://cocoadocs.org/docsets/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// GitHub
|
|
||||||
// https://github.com/jessesquires/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License
|
|
||||||
// Copyright (c) 2014 Jesse Squires
|
|
||||||
// Released under an MIT license: http://opensource.org/licenses/MIT
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
@interface UIColor (JSQMessages)
|
|
||||||
|
|
||||||
#pragma mark - Message bubble colors
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return A color object containing HSB values similar to the iOS 7 messages app green bubble color.
|
|
||||||
*/
|
|
||||||
+ (UIColor *)jsq_messageBubbleGreenColor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return A color object containing HSB values similar to the iOS 7 messages app blue bubble color.
|
|
||||||
*/
|
|
||||||
+ (UIColor *)jsq_messageBubbleBlueColor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return A color object containing HSB values similar to the iOS 7 red color.
|
|
||||||
*/
|
|
||||||
+ (UIColor *)jsq_messageBubbleRedColor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return A color object containing HSB values similar to the iOS 7 messages app light gray bubble color.
|
|
||||||
*/
|
|
||||||
+ (UIColor *)jsq_messageBubbleLightGrayColor;
|
|
||||||
|
|
||||||
#pragma mark - Utilities
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates and returns a new color object whose brightness component is decreased by the given value, using the initial color values of the receiver.
|
|
||||||
*
|
|
||||||
* @param value A floating point value describing the amount by which to decrease the brightness of the receiver.
|
|
||||||
*
|
|
||||||
* @return A new color object whose brightness is decreased by the given values. The other color values remain the same as the receiver.
|
|
||||||
*/
|
|
||||||
- (UIColor *)jsq_colorByDarkeningColorWithValue:(CGFloat)value;
|
|
||||||
|
|
||||||
@end
|
|
@ -1,90 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Jesse Squires
|
|
||||||
// http://www.jessesquires.com
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// Documentation
|
|
||||||
// http://cocoadocs.org/docsets/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// GitHub
|
|
||||||
// https://github.com/jessesquires/JSQMessagesViewController
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// License
|
|
||||||
// Copyright (c) 2014 Jesse Squires
|
|
||||||
// Released under an MIT license: http://opensource.org/licenses/MIT
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "UIColor+JSQMessages.h"
|
|
||||||
|
|
||||||
@implementation UIColor (JSQMessages)
|
|
||||||
|
|
||||||
#pragma mark - Message bubble colors
|
|
||||||
|
|
||||||
+ (UIColor *)jsq_messageBubbleGreenColor
|
|
||||||
{
|
|
||||||
return [UIColor colorWithHue:130.0f / 360.0f
|
|
||||||
saturation:0.68f
|
|
||||||
brightness:0.84f
|
|
||||||
alpha:1.0f];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (UIColor *)jsq_messageBubbleBlueColor
|
|
||||||
{
|
|
||||||
return [UIColor colorWithHue:210.0f / 360.0f
|
|
||||||
saturation:0.94f
|
|
||||||
brightness:1.0f
|
|
||||||
alpha:1.0f];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (UIColor *)jsq_messageBubbleRedColor
|
|
||||||
{
|
|
||||||
return [UIColor colorWithHue:0.0f / 360.0f
|
|
||||||
saturation:0.79f
|
|
||||||
brightness:1.0f
|
|
||||||
alpha:1.0f];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (UIColor *)jsq_messageBubbleLightGrayColor
|
|
||||||
{
|
|
||||||
return [UIColor colorWithHue:240.0f / 360.0f
|
|
||||||
saturation:0.02f
|
|
||||||
brightness:0.92f
|
|
||||||
alpha:1.0f];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Utilities
|
|
||||||
|
|
||||||
- (UIColor *)jsq_colorByDarkeningColorWithValue:(CGFloat)value
|
|
||||||
{
|
|
||||||
NSUInteger totalComponents = CGColorGetNumberOfComponents(self.CGColor);
|
|
||||||
BOOL isGreyscale = (totalComponents == 2) ? YES : NO;
|
|
||||||
|
|
||||||
CGFloat *oldComponents = (CGFloat *)CGColorGetComponents(self.CGColor);
|
|
||||||
CGFloat newComponents[4];
|
|
||||||
|
|
||||||
if (isGreyscale) {
|
|
||||||
newComponents[0] = oldComponents[0] - value < 0.0f ? 0.0f : oldComponents[0] - value;
|
|
||||||
newComponents[1] = oldComponents[0] - value < 0.0f ? 0.0f : oldComponents[0] - value;
|
|
||||||
newComponents[2] = oldComponents[0] - value < 0.0f ? 0.0f : oldComponents[0] - value;
|
|
||||||
newComponents[3] = oldComponents[1];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
newComponents[0] = oldComponents[0] - value < 0.0f ? 0.0f : oldComponents[0] - value;
|
|
||||||
newComponents[1] = oldComponents[1] - value < 0.0f ? 0.0f : oldComponents[1] - value;
|
|
||||||
newComponents[2] = oldComponents[2] - value < 0.0f ? 0.0f : oldComponents[2] - value;
|
|
||||||
newComponents[3] = oldComponents[3];
|
|
||||||
}
|
|
||||||
|
|
||||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
||||||
CGColorRef newColor = CGColorCreate(colorSpace, newComponents);
|
|
||||||
CGColorSpaceRelease(colorSpace);
|
|
||||||
|
|
||||||
UIColor *retColor = [UIColor colorWithCGColor:newColor];
|
|
||||||
CGColorRelease(newColor);
|
|
||||||
|
|
||||||
return retColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
Loading…
Reference in New Issue