Replace ActiveLabel-based implementation with TTTAttributedLabel
This commit is contained in:
parent
fa002fbed6
commit
13cd0f6535
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,777 @@
|
|||
// TTTAttributedLabel.h
|
||||
//
|
||||
// Copyright (c) 2011 Mattt Thompson (http://mattt.me)
|
||||
//
|
||||
// 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.
|
||||
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <CoreText/CoreText.h>
|
||||
|
||||
|
||||
//! Project version number for TTTAttributedLabel.
|
||||
FOUNDATION_EXPORT double TTTAttributedLabelVersionNumber;
|
||||
|
||||
|
||||
//! Project version string for TTTAttributedLabel.
|
||||
FOUNDATION_EXPORT const unsigned char TTTAttributedLabelVersionString[];
|
||||
|
||||
|
||||
@class TTTAttributedLabelLink;
|
||||
|
||||
|
||||
/**
|
||||
Vertical alignment for text in a label whose bounds are larger than its text bounds
|
||||
*/
|
||||
typedef NS_ENUM(NSInteger, TTTAttributedLabelVerticalAlignment) {
|
||||
TTTAttributedLabelVerticalAlignmentCenter = 0,
|
||||
TTTAttributedLabelVerticalAlignmentTop = 1,
|
||||
TTTAttributedLabelVerticalAlignmentBottom = 2,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Determines whether the text to which this attribute applies has a strikeout drawn through itself.
|
||||
*/
|
||||
extern NSString * const kTTTStrikeOutAttributeName;
|
||||
|
||||
|
||||
/**
|
||||
The background fill color. Value must be a `CGColorRef`. Default value is `nil` (no fill).
|
||||
*/
|
||||
extern NSString * const kTTTBackgroundFillColorAttributeName;
|
||||
|
||||
|
||||
/**
|
||||
The padding for the background fill. Value must be a `UIEdgeInsets`. Default value is `UIEdgeInsetsZero` (no padding).
|
||||
*/
|
||||
extern NSString * const kTTTBackgroundFillPaddingAttributeName;
|
||||
|
||||
|
||||
/**
|
||||
The background stroke color. Value must be a `CGColorRef`. Default value is `nil` (no stroke).
|
||||
*/
|
||||
extern NSString * const kTTTBackgroundStrokeColorAttributeName;
|
||||
|
||||
|
||||
/**
|
||||
The background stroke line width. Value must be an `NSNumber`. Default value is `1.0f`.
|
||||
*/
|
||||
extern NSString * const kTTTBackgroundLineWidthAttributeName;
|
||||
|
||||
|
||||
/**
|
||||
The background corner radius. Value must be an `NSNumber`. Default value is `5.0f`.
|
||||
*/
|
||||
extern NSString * const kTTTBackgroundCornerRadiusAttributeName;
|
||||
|
||||
|
||||
@protocol TTTAttributedLabelDelegate;
|
||||
|
||||
|
||||
// Override UILabel @property to accept both NSString and NSAttributedString
|
||||
@protocol TTTAttributedLabel <NSObject>
|
||||
@property (nonatomic, copy) IBInspectable id text;
|
||||
@end
|
||||
|
||||
|
||||
IB_DESIGNABLE
|
||||
|
||||
|
||||
/**
|
||||
`TTTAttributedLabel` is a drop-in replacement for `UILabel` that supports `NSAttributedString`, as well as automatically-detected and manually-added links to URLs, addresses, phone numbers, and dates.
|
||||
|
||||
## Differences Between `TTTAttributedLabel` and `UILabel`
|
||||
|
||||
For the most part, `TTTAttributedLabel` behaves just like `UILabel`. The following are notable exceptions, in which `TTTAttributedLabel` may act differently:
|
||||
|
||||
- `text` - This property now takes an `id` type argument, which can either be a kind of `NSString` or `NSAttributedString` (mutable or immutable in both cases)
|
||||
- `attributedText` - Do not set this property directly. Instead, pass an `NSAttributedString` to `text`.
|
||||
- `lineBreakMode` - This property displays only the first line when the value is `UILineBreakModeHeadTruncation`, `UILineBreakModeTailTruncation`, or `UILineBreakModeMiddleTruncation`
|
||||
- `adjustsFontsizeToFitWidth` - Supported in iOS 5 and greater, this property is effective for any value of `numberOfLines` greater than zero. In iOS 4, setting `numberOfLines` to a value greater than 1 with `adjustsFontSizeToFitWidth` set to `YES` may cause `sizeToFit` to execute indefinitely.
|
||||
- `baselineAdjustment` - This property has no affect.
|
||||
- `textAlignment` - This property does not support justified alignment.
|
||||
- `NSTextAttachment` - This string attribute is not supported.
|
||||
|
||||
Any properties affecting text or paragraph styling, such as `firstLineIndent` will only apply when text is set with an `NSString`. If the text is set with an `NSAttributedString`, these properties will not apply.
|
||||
|
||||
### NSCoding
|
||||
|
||||
`TTTAttributedLabel`, like `UILabel`, conforms to `NSCoding`. However, if the build target is set to less than iOS 6.0, `linkAttributes` and `activeLinkAttributes` will not be encoded or decoded. This is due to an runtime exception thrown when attempting to copy non-object CoreText values in dictionaries.
|
||||
|
||||
@warning Any properties changed on the label after setting the text will not be reflected until a subsequent call to `setText:` or `setText:afterInheritingLabelAttributesAndConfiguringWithBlock:`. This is to say, order of operations matters in this case. For example, if the label text color is originally black when the text is set, changing the text color to red will have no effect on the display of the label until the text is set once again.
|
||||
|
||||
@bug Setting `attributedText` directly is not recommended, as it may cause a crash when attempting to access any links previously set. Instead, call `setText:`, passing an `NSAttributedString`.
|
||||
*/
|
||||
@interface TTTAttributedLabel : UILabel <TTTAttributedLabel, UIGestureRecognizerDelegate>
|
||||
|
||||
|
||||
/**
|
||||
* The designated initializers are @c initWithFrame: and @c initWithCoder:.
|
||||
* init will not properly initialize many required properties and other configuration.
|
||||
*/
|
||||
- (instancetype) init NS_UNAVAILABLE;
|
||||
|
||||
|
||||
///-----------------------------
|
||||
/// @name Accessing the Delegate
|
||||
///-----------------------------
|
||||
|
||||
|
||||
/**
|
||||
The receiver's delegate.
|
||||
|
||||
@discussion A `TTTAttributedLabel` delegate responds to messages sent by tapping on links in the label. You can use the delegate to respond to links referencing a URL, address, phone number, date, or date with a specified time zone and duration.
|
||||
*/
|
||||
@property (nonatomic, unsafe_unretained) IBOutlet id <TTTAttributedLabelDelegate> delegate;
|
||||
|
||||
|
||||
///--------------------------------------------
|
||||
/// @name Detecting, Accessing, & Styling Links
|
||||
///--------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
A bitmask of `NSTextCheckingType` which are used to automatically detect links in the label text.
|
||||
|
||||
@warning You must specify `enabledTextCheckingTypes` before setting the `text`, with either `setText:` or `setText:afterInheritingLabelAttributesAndConfiguringWithBlock:`.
|
||||
*/
|
||||
@property (nonatomic, assign) NSTextCheckingTypes enabledTextCheckingTypes;
|
||||
|
||||
|
||||
/**
|
||||
An array of `NSTextCheckingResult` objects for links detected or manually added to the label text.
|
||||
*/
|
||||
@property (readonly, nonatomic, strong) NSArray *links;
|
||||
|
||||
|
||||
/**
|
||||
A dictionary containing the default `NSAttributedString` attributes to be applied to links detected or manually added to the label text. The default link style is blue and underlined.
|
||||
|
||||
@warning You must specify `linkAttributes` before setting autodecting or manually-adding links for these attributes to be applied.
|
||||
*/
|
||||
@property (nonatomic, strong) NSDictionary *linkAttributes;
|
||||
|
||||
|
||||
/**
|
||||
A dictionary containing the default `NSAttributedString` attributes to be applied to links when they are in the active state. If `nil` or an empty `NSDictionary`, active links will not be styled. The default active link style is red and underlined.
|
||||
*/
|
||||
@property (nonatomic, strong) NSDictionary *activeLinkAttributes;
|
||||
|
||||
|
||||
/**
|
||||
A dictionary containing the default `NSAttributedString` attributes to be applied to links when they are in the inactive state, which is triggered by a change in `tintColor` in iOS 7 and later. If `nil` or an empty `NSDictionary`, inactive links will not be styled. The default inactive link style is gray and unadorned.
|
||||
*/
|
||||
@property (nonatomic, strong) NSDictionary *inactiveLinkAttributes;
|
||||
|
||||
|
||||
/**
|
||||
The edge inset for the background of a link. The default value is `{0, -1, 0, -1}`.
|
||||
*/
|
||||
@property (nonatomic, assign) UIEdgeInsets linkBackgroundEdgeInset;
|
||||
|
||||
|
||||
/**
|
||||
Indicates if links will be detected within an extended area around the touch
|
||||
to emulate the link detection behaviour of UIWebView.
|
||||
Default value is NO. Enabling this may adversely impact performance.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL extendsLinkTouchArea;
|
||||
|
||||
|
||||
///---------------------------------------
|
||||
/// @name Acccessing Text Style Attributes
|
||||
///---------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
The shadow blur radius for the label. A value of 0 indicates no blur, while larger values produce correspondingly larger blurring. This value must not be negative. The default value is 0.
|
||||
*/
|
||||
@property (nonatomic, assign) IBInspectable CGFloat shadowRadius;
|
||||
|
||||
|
||||
/**
|
||||
The shadow blur radius for the label when the label's `highlighted` property is `YES`. A value of 0 indicates no blur, while larger values produce correspondingly larger blurring. This value must not be negative. The default value is 0.
|
||||
*/
|
||||
@property (nonatomic, assign) IBInspectable CGFloat highlightedShadowRadius;
|
||||
/**
|
||||
The shadow offset for the label when the label's `highlighted` property is `YES`. A size of {0, 0} indicates no offset, with positive values extending down and to the right. The default size is {0, 0}.
|
||||
*/
|
||||
@property (nonatomic, assign) IBInspectable CGSize highlightedShadowOffset;
|
||||
/**
|
||||
The shadow color for the label when the label's `highlighted` property is `YES`. The default value is `nil` (no shadow color).
|
||||
*/
|
||||
@property (nonatomic, strong) IBInspectable UIColor *highlightedShadowColor;
|
||||
|
||||
|
||||
/**
|
||||
The amount to kern the next character. Default is standard kerning. If this attribute is set to 0.0, no kerning is done at all.
|
||||
*/
|
||||
@property (nonatomic, assign) IBInspectable CGFloat kern;
|
||||
|
||||
|
||||
///--------------------------------------------
|
||||
/// @name Acccessing Paragraph Style Attributes
|
||||
///--------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
The distance, in points, from the leading margin of a frame to the beginning of the
|
||||
paragraph's first line. This value is always nonnegative, and is 0.0 by default.
|
||||
This applies to the full text, rather than any specific paragraph metrics.
|
||||
*/
|
||||
@property (nonatomic, assign) IBInspectable CGFloat firstLineIndent;
|
||||
|
||||
|
||||
/**
|
||||
The space in points added between lines within the paragraph. This value is always nonnegative and is 0.0 by default.
|
||||
*/
|
||||
@property (nonatomic, assign) IBInspectable CGFloat lineSpacing;
|
||||
|
||||
|
||||
/**
|
||||
The minimum line height within the paragraph. If the value is 0.0, the minimum line height is set to the line height of the `font`. 0.0 by default.
|
||||
*/
|
||||
@property (nonatomic, assign) IBInspectable CGFloat minimumLineHeight;
|
||||
|
||||
|
||||
/**
|
||||
The maximum line height within the paragraph. If the value is 0.0, the maximum line height is set to the line height of the `font`. 0.0 by default.
|
||||
*/
|
||||
@property (nonatomic, assign) IBInspectable CGFloat maximumLineHeight;
|
||||
|
||||
|
||||
/**
|
||||
The line height multiple. This value is 1.0 by default.
|
||||
*/
|
||||
@property (nonatomic, assign) IBInspectable CGFloat lineHeightMultiple;
|
||||
|
||||
|
||||
/**
|
||||
The distance, in points, from the margin to the text container. This value is `UIEdgeInsetsZero` by default.
|
||||
sizeThatFits: will have its returned size increased by these margins.
|
||||
drawTextInRect: will inset all drawn text by these margins.
|
||||
*/
|
||||
@property (nonatomic, assign) IBInspectable UIEdgeInsets textInsets;
|
||||
|
||||
|
||||
/**
|
||||
The vertical text alignment for the label, for when the frame size is greater than the text rect size. The vertical alignment is `TTTAttributedLabelVerticalAlignmentCenter` by default.
|
||||
*/
|
||||
@property (nonatomic, assign) TTTAttributedLabelVerticalAlignment verticalAlignment;
|
||||
|
||||
|
||||
///--------------------------------------------
|
||||
/// @name Accessing Truncation Token Appearance
|
||||
///--------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
The attributed string to apply to the truncation token at the end of a truncated line.
|
||||
*/
|
||||
@property (nonatomic, strong) IBInspectable NSAttributedString *attributedTruncationToken;
|
||||
|
||||
|
||||
///--------------------------
|
||||
/// @name Long press gestures
|
||||
///--------------------------
|
||||
|
||||
|
||||
/**
|
||||
* The long-press gesture recognizer used internally by the label.
|
||||
*/
|
||||
@property (nonatomic, strong, readonly) UILongPressGestureRecognizer *longPressGestureRecognizer;
|
||||
|
||||
|
||||
///--------------------------------------------
|
||||
/// @name Calculating Size of Attributed String
|
||||
///--------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
Calculate and return the size that best fits an attributed string, given the specified constraints on size and number of lines.
|
||||
|
||||
@param attributedString The attributed string.
|
||||
@param size The maximum dimensions used to calculate size.
|
||||
@param numberOfLines The maximum number of lines in the text to draw, if the constraining size cannot accomodate the full attributed string.
|
||||
|
||||
@return The size that fits the attributed string within the specified constraints.
|
||||
*/
|
||||
+ (CGSize)sizeThatFitsAttributedString:(NSAttributedString *)attributedString
|
||||
withConstraints:(CGSize)size
|
||||
limitedToNumberOfLines:(NSUInteger)numberOfLines;
|
||||
|
||||
|
||||
///----------------------------------
|
||||
/// @name Setting the Text Attributes
|
||||
///----------------------------------
|
||||
|
||||
|
||||
/**
|
||||
Sets the text displayed by the label.
|
||||
|
||||
@param text An `NSString` or `NSAttributedString` object to be displayed by the label. If the specified text is an `NSString`, the label will display the text like a `UILabel`, inheriting the text styles of the label. If the specified text is an `NSAttributedString`, the label text styles will be overridden by the styles specified in the attributed string.
|
||||
|
||||
@discussion This method overrides `UILabel -setText:` to accept both `NSString` and `NSAttributedString` objects. This string is `nil` by default.
|
||||
*/
|
||||
- (void)setText:(id)text;
|
||||
|
||||
|
||||
/**
|
||||
Sets the text displayed by the label, after configuring an attributed string containing the text attributes inherited from the label in a block.
|
||||
|
||||
@param text An `NSString` or `NSAttributedString` object to be displayed by the label.
|
||||
@param block A block object that returns an `NSMutableAttributedString` object and takes a single argument, which is an `NSMutableAttributedString` object with the text from the first parameter, and the text attributes inherited from the label text styles. For example, if you specified the `font` of the label to be `[UIFont boldSystemFontOfSize:14]` and `textColor` to be `[UIColor redColor]`, the `NSAttributedString` argument of the block would be contain the `NSAttributedString` attribute equivalents of those properties. In this block, you can set further attributes on particular ranges.
|
||||
|
||||
@discussion This string is `nil` by default.
|
||||
*/
|
||||
- (void)setText:(id)text
|
||||
afterInheritingLabelAttributesAndConfiguringWithBlock:(NSMutableAttributedString *(^)(NSMutableAttributedString *mutableAttributedString))block;
|
||||
|
||||
|
||||
///------------------------------------
|
||||
/// @name Accessing the Text Attributes
|
||||
///------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
A copy of the label's current attributedText. This returns `nil` if an attributed string has never been set on the label.
|
||||
|
||||
@warning Do not set this property directly. Instead, set @c text to an @c NSAttributedString.
|
||||
*/
|
||||
@property (readwrite, nonatomic, copy) NSAttributedString *attributedText;
|
||||
|
||||
|
||||
///-------------------
|
||||
/// @name Adding Links
|
||||
///-------------------
|
||||
|
||||
|
||||
/**
|
||||
Adds a link. You can customize an individual link's appearance and accessibility value by creating your own @c TTTAttributedLabelLink and passing it to this method. The other methods for adding links will use the label's default attributes.
|
||||
|
||||
@warning Modifying the link's attribute dictionaries must be done before calling this method.
|
||||
|
||||
@param link A @c TTTAttributedLabelLink object.
|
||||
*/
|
||||
- (void)addLink:(TTTAttributedLabelLink *)link;
|
||||
|
||||
|
||||
/**
|
||||
Adds a link to an @c NSTextCheckingResult.
|
||||
|
||||
@param result An @c NSTextCheckingResult representing the link's location and type.
|
||||
|
||||
@return The newly added link object.
|
||||
*/
|
||||
- (TTTAttributedLabelLink *)addLinkWithTextCheckingResult:(NSTextCheckingResult *)result;
|
||||
|
||||
|
||||
/**
|
||||
Adds a link to an @c NSTextCheckingResult.
|
||||
|
||||
@param result An @c NSTextCheckingResult representing the link's location and type.
|
||||
@param attributes The attributes to be added to the text in the range of the specified link. If set, the label's @c activeAttributes and @c inactiveAttributes will be applied to the link. If `nil`, no attributes are added to the link.
|
||||
|
||||
@return The newly added link object.
|
||||
*/
|
||||
- (TTTAttributedLabelLink *)addLinkWithTextCheckingResult:(NSTextCheckingResult *)result
|
||||
attributes:(NSDictionary *)attributes;
|
||||
|
||||
|
||||
/**
|
||||
Adds a link to a URL for a specified range in the label text.
|
||||
|
||||
@param url The url to be linked to
|
||||
@param range The range in the label text of the link. The range must not exceed the bounds of the receiver.
|
||||
|
||||
@return The newly added link object.
|
||||
*/
|
||||
- (TTTAttributedLabelLink *)addLinkToURL:(NSURL *)url
|
||||
withRange:(NSRange)range;
|
||||
|
||||
|
||||
/**
|
||||
Adds a link to an address for a specified range in the label text.
|
||||
|
||||
@param addressComponents A dictionary of address components for the address to be linked to
|
||||
@param range The range in the label text of the link. The range must not exceed the bounds of the receiver.
|
||||
|
||||
@discussion The address component dictionary keys are described in `NSTextCheckingResult`'s "Keys for Address Components."
|
||||
|
||||
@return The newly added link object.
|
||||
*/
|
||||
- (TTTAttributedLabelLink *)addLinkToAddress:(NSDictionary *)addressComponents
|
||||
withRange:(NSRange)range;
|
||||
|
||||
|
||||
/**
|
||||
Adds a link to a phone number for a specified range in the label text.
|
||||
|
||||
@param phoneNumber The phone number to be linked to.
|
||||
@param range The range in the label text of the link. The range must not exceed the bounds of the receiver.
|
||||
|
||||
@return The newly added link object.
|
||||
*/
|
||||
- (TTTAttributedLabelLink *)addLinkToPhoneNumber:(NSString *)phoneNumber
|
||||
withRange:(NSRange)range;
|
||||
|
||||
|
||||
/**
|
||||
Adds a link to a date for a specified range in the label text.
|
||||
|
||||
@param date The date to be linked to.
|
||||
@param range The range in the label text of the link. The range must not exceed the bounds of the receiver.
|
||||
|
||||
@return The newly added link object.
|
||||
*/
|
||||
- (TTTAttributedLabelLink *)addLinkToDate:(NSDate *)date
|
||||
withRange:(NSRange)range;
|
||||
|
||||
|
||||
/**
|
||||
Adds a link to a date with a particular time zone and duration for a specified range in the label text.
|
||||
|
||||
@param date The date to be linked to.
|
||||
@param timeZone The time zone of the specified date.
|
||||
@param duration The duration, in seconds from the specified date.
|
||||
@param range The range in the label text of the link. The range must not exceed the bounds of the receiver.
|
||||
|
||||
@return The newly added link object.
|
||||
*/
|
||||
- (TTTAttributedLabelLink *)addLinkToDate:(NSDate *)date
|
||||
timeZone:(NSTimeZone *)timeZone
|
||||
duration:(NSTimeInterval)duration
|
||||
withRange:(NSRange)range;
|
||||
|
||||
|
||||
/**
|
||||
Adds a link to transit information for a specified range in the label text.
|
||||
|
||||
@param components A dictionary containing the transit components. The currently supported keys are `NSTextCheckingAirlineKey` and `NSTextCheckingFlightKey`.
|
||||
@param range The range in the label text of the link. The range must not exceed the bounds of the receiver.
|
||||
|
||||
@return The newly added link object.
|
||||
*/
|
||||
- (TTTAttributedLabelLink *)addLinkToTransitInformation:(NSDictionary *)components
|
||||
withRange:(NSRange)range;
|
||||
|
||||
|
||||
/**
|
||||
Returns whether an @c NSTextCheckingResult is found at the give point.
|
||||
|
||||
@discussion This can be used together with @c UITapGestureRecognizer to tap interactions with overlapping views.
|
||||
|
||||
@param point The point inside the label.
|
||||
*/
|
||||
- (BOOL)containslinkAtPoint:(CGPoint)point;
|
||||
|
||||
|
||||
/**
|
||||
Returns the @c TTTAttributedLabelLink at the give point if it exists.
|
||||
|
||||
@discussion This can be used together with @c UIViewControllerPreviewingDelegate to peek into links.
|
||||
|
||||
@param point The point inside the label.
|
||||
*/
|
||||
- (TTTAttributedLabelLink *)linkAtPoint:(CGPoint)point;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
The `TTTAttributedLabelDelegate` protocol defines the messages sent to an attributed label delegate when links are tapped. All of the methods of this protocol are optional.
|
||||
*/
|
||||
@protocol TTTAttributedLabelDelegate <NSObject>
|
||||
|
||||
|
||||
///-----------------------------------
|
||||
/// @name Responding to Link Selection
|
||||
///-----------------------------------
|
||||
@optional
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user did select a link to a URL.
|
||||
|
||||
@param label The label whose link was selected.
|
||||
@param url The URL for the selected link.
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didSelectLinkWithURL:(NSURL *)url;
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user did select a link to an address.
|
||||
|
||||
@param label The label whose link was selected.
|
||||
@param addressComponents The components of the address for the selected link.
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didSelectLinkWithAddress:(NSDictionary *)addressComponents;
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user did select a link to a phone number.
|
||||
|
||||
@param label The label whose link was selected.
|
||||
@param phoneNumber The phone number for the selected link.
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didSelectLinkWithPhoneNumber:(NSString *)phoneNumber;
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user did select a link to a date.
|
||||
|
||||
@param label The label whose link was selected.
|
||||
@param date The datefor the selected link.
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didSelectLinkWithDate:(NSDate *)date;
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user did select a link to a date with a time zone and duration.
|
||||
|
||||
@param label The label whose link was selected.
|
||||
@param date The date for the selected link.
|
||||
@param timeZone The time zone of the date for the selected link.
|
||||
@param duration The duration, in seconds from the date for the selected link.
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didSelectLinkWithDate:(NSDate *)date
|
||||
timeZone:(NSTimeZone *)timeZone
|
||||
duration:(NSTimeInterval)duration;
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user did select a link to transit information
|
||||
|
||||
@param label The label whose link was selected.
|
||||
@param components A dictionary containing the transit components. The currently supported keys are `NSTextCheckingAirlineKey` and `NSTextCheckingFlightKey`.
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didSelectLinkWithTransitInformation:(NSDictionary *)components;
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user did select a link to a text checking result.
|
||||
|
||||
@discussion This method is called if no other delegate method was called, which can occur by either now implementing the method in `TTTAttributedLabelDelegate` corresponding to a particular link, or the link was added by passing an instance of a custom `NSTextCheckingResult` subclass into `-addLinkWithTextCheckingResult:`.
|
||||
|
||||
@param label The label whose link was selected.
|
||||
@param result The custom text checking result.
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didSelectLinkWithTextCheckingResult:(NSTextCheckingResult *)result;
|
||||
|
||||
|
||||
///---------------------------------
|
||||
/// @name Responding to Long Presses
|
||||
///---------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Long-press delegate methods include the CGPoint tapped within the label's coordinate space.
|
||||
* This may be useful on iPad to present a popover from a specific origin point.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user long-pressed a link to a URL.
|
||||
|
||||
@param label The label whose link was long pressed.
|
||||
@param url The URL for the link.
|
||||
@param point the point pressed, in the label's coordinate space
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didLongPressLinkWithURL:(NSURL *)url
|
||||
atPoint:(CGPoint)point;
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user long-pressed a link to an address.
|
||||
|
||||
@param label The label whose link was long pressed.
|
||||
@param addressComponents The components of the address for the link.
|
||||
@param point the point pressed, in the label's coordinate space
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didLongPressLinkWithAddress:(NSDictionary *)addressComponents
|
||||
atPoint:(CGPoint)point;
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user long-pressed a link to a phone number.
|
||||
|
||||
@param label The label whose link was long pressed.
|
||||
@param phoneNumber The phone number for the link.
|
||||
@param point the point pressed, in the label's coordinate space
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didLongPressLinkWithPhoneNumber:(NSString *)phoneNumber
|
||||
atPoint:(CGPoint)point;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user long-pressed a link to a date.
|
||||
|
||||
@param label The label whose link was long pressed.
|
||||
@param date The date for the selected link.
|
||||
@param point the point pressed, in the label's coordinate space
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didLongPressLinkWithDate:(NSDate *)date
|
||||
atPoint:(CGPoint)point;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user long-pressed a link to a date with a time zone and duration.
|
||||
|
||||
@param label The label whose link was long pressed.
|
||||
@param date The date for the link.
|
||||
@param timeZone The time zone of the date for the link.
|
||||
@param duration The duration, in seconds from the date for the link.
|
||||
@param point the point pressed, in the label's coordinate space
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didLongPressLinkWithDate:(NSDate *)date
|
||||
timeZone:(NSTimeZone *)timeZone
|
||||
duration:(NSTimeInterval)duration
|
||||
atPoint:(CGPoint)point;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user long-pressed a link to transit information.
|
||||
|
||||
@param label The label whose link was long pressed.
|
||||
@param components A dictionary containing the transit components. The currently supported keys are `NSTextCheckingAirlineKey` and `NSTextCheckingFlightKey`.
|
||||
@param point the point pressed, in the label's coordinate space
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didLongPressLinkWithTransitInformation:(NSDictionary *)components
|
||||
atPoint:(CGPoint)point;
|
||||
|
||||
|
||||
/**
|
||||
Tells the delegate that the user long-pressed a link to a text checking result.
|
||||
|
||||
@discussion Similar to `-attributedLabel:didSelectLinkWithTextCheckingResult:`, this method is called if a link is long pressed and the delegate does not implement the method corresponding to this type of link.
|
||||
|
||||
@param label The label whose link was long pressed.
|
||||
@param result The custom text checking result.
|
||||
@param point the point pressed, in the label's coordinate space
|
||||
*/
|
||||
- (void)attributedLabel:(TTTAttributedLabel *)label
|
||||
didLongPressLinkWithTextCheckingResult:(NSTextCheckingResult *)result
|
||||
atPoint:(CGPoint)point;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface TTTAttributedLabelLink : NSObject <NSCoding>
|
||||
|
||||
|
||||
typedef void (^TTTAttributedLabelLinkBlock) (TTTAttributedLabel *, TTTAttributedLabelLink *);
|
||||
|
||||
|
||||
/**
|
||||
An `NSTextCheckingResult` representing the link's location and type.
|
||||
*/
|
||||
@property (readonly, nonatomic, strong) NSTextCheckingResult *result;
|
||||
|
||||
|
||||
/**
|
||||
A dictionary containing the @c NSAttributedString attributes to be applied to the link.
|
||||
*/
|
||||
@property (readonly, nonatomic, copy) NSDictionary *attributes;
|
||||
|
||||
|
||||
/**
|
||||
A dictionary containing the @c NSAttributedString attributes to be applied to the link when it is in the active state.
|
||||
*/
|
||||
@property (readonly, nonatomic, copy) NSDictionary *activeAttributes;
|
||||
|
||||
|
||||
/**
|
||||
A dictionary containing the @c NSAttributedString attributes to be applied to the link when it is in the inactive state, which is triggered by a change in `tintColor` in iOS 7 and later.
|
||||
*/
|
||||
@property (readonly, nonatomic, copy) NSDictionary *inactiveAttributes;
|
||||
|
||||
|
||||
/**
|
||||
Additional information about a link for VoiceOver users. Has default values if the link's @c result is @c NSTextCheckingTypeLink, @c NSTextCheckingTypePhoneNumber, or @c NSTextCheckingTypeDate.
|
||||
*/
|
||||
@property (nonatomic, copy) NSString *accessibilityValue;
|
||||
|
||||
|
||||
/**
|
||||
A block called when this link is tapped.
|
||||
If non-nil, tapping on this link will call this block instead of the
|
||||
@c TTTAttributedLabelDelegate tap methods, which will not be called for this link.
|
||||
*/
|
||||
@property (nonatomic, copy) TTTAttributedLabelLinkBlock linkTapBlock;
|
||||
|
||||
|
||||
/**
|
||||
A block called when this link is long-pressed.
|
||||
If non-nil, long pressing on this link will call this block instead of the
|
||||
@c TTTAttributedLabelDelegate long press methods, which will not be called for this link.
|
||||
*/
|
||||
@property (nonatomic, copy) TTTAttributedLabelLinkBlock linkLongPressBlock;
|
||||
|
||||
|
||||
/**
|
||||
Initializes a link using the attribute dictionaries specified.
|
||||
|
||||
@param attributes The @c attributes property for the link.
|
||||
@param activeAttributes The @c activeAttributes property for the link.
|
||||
@param inactiveAttributes The @c inactiveAttributes property for the link.
|
||||
@param result An @c NSTextCheckingResult representing the link's location and type.
|
||||
|
||||
@return The initialized link object.
|
||||
*/
|
||||
- (instancetype)initWithAttributes:(NSDictionary *)attributes
|
||||
activeAttributes:(NSDictionary *)activeAttributes
|
||||
inactiveAttributes:(NSDictionary *)inactiveAttributes
|
||||
textCheckingResult:(NSTextCheckingResult *)result;
|
||||
|
||||
|
||||
/**
|
||||
Initializes a link using the attribute dictionaries set on a specified label.
|
||||
|
||||
@param label The attributed label from which to inherit attribute dictionaries.
|
||||
@param result An @c NSTextCheckingResult representing the link's location and type.
|
||||
|
||||
@return The initialized link object.
|
||||
*/
|
||||
- (instancetype)initWithAttributesFromLabel:(TTTAttributedLabel*)label
|
||||
textCheckingResult:(NSTextCheckingResult *)result;
|
||||
|
||||
|
||||
@end
|
File diff suppressed because it is too large
Load Diff
|
@ -7,6 +7,11 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
04496BCC216252E5001F1B23 /* TTTAttributedLabel.h in Headers */ = {isa = PBXBuildFile; fileRef = 04496BCA216252E5001F1B23 /* TTTAttributedLabel.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
04496BCF216252E5001F1B23 /* TTTAttributedLabel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04496BC8216252E5001F1B23 /* TTTAttributedLabel.framework */; };
|
||||
04496BD0216252E5001F1B23 /* TTTAttributedLabel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 04496BC8216252E5001F1B23 /* TTTAttributedLabel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
04496BD52162530A001F1B23 /* TTTAttributedLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 04496BD42162530A001F1B23 /* TTTAttributedLabel.m */; };
|
||||
04496BD721625361001F1B23 /* ContentLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04496BD621625361001F1B23 /* ContentLabel.swift */; };
|
||||
04DACE8C212CB14B009840C4 /* MainTabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DACE8B212CB14B009840C4 /* MainTabBarViewController.swift */; };
|
||||
04DACE8E212CC7CC009840C4 /* AvatarCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DACE8D212CC7CC009840C4 /* AvatarCache.swift */; };
|
||||
04ED00B121481ED800567C53 /* SteppedProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04ED00B021481ED800567C53 /* SteppedProgressView.swift */; };
|
||||
|
@ -65,7 +70,6 @@
|
|||
D646C956213B365700269FB5 /* LargeImageExpandAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646C955213B365700269FB5 /* LargeImageExpandAnimationController.swift */; };
|
||||
D646C958213B367000269FB5 /* LargeImageShrinkAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646C957213B367000269FB5 /* LargeImageShrinkAnimationController.swift */; };
|
||||
D646C95A213B5D0500269FB5 /* LargeImageInteractionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D646C959213B5D0500269FB5 /* LargeImageInteractionController.swift */; };
|
||||
D64A0CD32132153900640E3B /* HTMLContentLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64A0CD22132153900640E3B /* HTMLContentLabel.swift */; };
|
||||
D64D0AAD2128D88B005A6F37 /* LocalData.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64D0AAC2128D88B005A6F37 /* LocalData.swift */; };
|
||||
D64D0AAF2128D954005A6F37 /* Onboarding.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D64D0AAE2128D954005A6F37 /* Onboarding.storyboard */; };
|
||||
D64D0AB12128D9AE005A6F37 /* OnboardingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D64D0AB02128D9AE005A6F37 /* OnboardingViewController.swift */; };
|
||||
|
@ -88,7 +92,6 @@
|
|||
D667E5E721349D4C0057A976 /* ProfileTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5E621349D4C0057A976 /* ProfileTableViewController.swift */; };
|
||||
D667E5E921349EE50057A976 /* ProfileHeaderTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D667E5E821349EE50057A976 /* ProfileHeaderTableViewCell.xib */; };
|
||||
D667E5EB21349EF80057A976 /* ProfileHeaderTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5EA21349EF80057A976 /* ProfileHeaderTableViewCell.swift */; };
|
||||
D667E5EF2134C39F0057A976 /* StatusContentLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5EE2134C39F0057A976 /* StatusContentLabel.swift */; };
|
||||
D667E5F12134D5050057A976 /* UIViewController+Delegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5F02134D5050057A976 /* UIViewController+Delegates.swift */; };
|
||||
D667E5F32135BC260057A976 /* Conversation.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D667E5F22135BC260057A976 /* Conversation.storyboard */; };
|
||||
D667E5F52135BCD50057A976 /* ConversationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D667E5F42135BCD50057A976 /* ConversationViewController.swift */; };
|
||||
|
@ -103,6 +106,7 @@
|
|||
D6C693CD2161257B007D6A6D /* SilentActionPermissionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D6C693CC2161257B007D6A6D /* SilentActionPermissionCell.xib */; };
|
||||
D6C693CF216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693CE216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift */; };
|
||||
D6C693EF216192C2007D6A6D /* TuskerNavigationDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693EE216192C2007D6A6D /* TuskerNavigationDelegate.swift */; };
|
||||
D6C693F92162E4DB007D6A6D /* StatusContentLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C693F82162E4DB007D6A6D /* StatusContentLabel.swift */; };
|
||||
D6C94D852139DFD800CB5196 /* LargeImage.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D6C94D842139DFD800CB5196 /* LargeImage.storyboard */; };
|
||||
D6C94D872139E62700CB5196 /* LargeImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C94D862139E62700CB5196 /* LargeImageViewController.swift */; };
|
||||
D6C94D892139E6EC00CB5196 /* AttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6C94D882139E6EC00CB5196 /* AttachmentView.swift */; };
|
||||
|
@ -120,6 +124,13 @@
|
|||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
04496BCD216252E5001F1B23 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = D6D4DDC4212518A000E1C4BB /* Project object */;
|
||||
proxyType = 1;
|
||||
remoteGlobalIDString = 04496BC7216252E5001F1B23;
|
||||
remoteInfo = TTTAttributedLabel;
|
||||
};
|
||||
D61099B52144B0CC00432DC2 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = D6D4DDC4212518A000E1C4BB /* Project object */;
|
||||
|
@ -164,6 +175,7 @@
|
|||
dstPath = "";
|
||||
dstSubfolderSpec = 10;
|
||||
files = (
|
||||
04496BD0216252E5001F1B23 /* TTTAttributedLabel.framework in Embed Frameworks */,
|
||||
D61099C12144B0CC00432DC2 /* Pachyderm.framework in Embed Frameworks */,
|
||||
D6BED170212663DA00F02DA0 /* SwiftSoup.framework in Embed Frameworks */,
|
||||
);
|
||||
|
@ -173,6 +185,11 @@
|
|||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
04496BC8216252E5001F1B23 /* TTTAttributedLabel.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TTTAttributedLabel.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
04496BCA216252E5001F1B23 /* TTTAttributedLabel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TTTAttributedLabel.h; sourceTree = "<group>"; };
|
||||
04496BCB216252E5001F1B23 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
04496BD42162530A001F1B23 /* TTTAttributedLabel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TTTAttributedLabel.m; sourceTree = "<group>"; };
|
||||
04496BD621625361001F1B23 /* ContentLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentLabel.swift; sourceTree = "<group>"; };
|
||||
04DACE8B212CB14B009840C4 /* MainTabBarViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarViewController.swift; sourceTree = "<group>"; };
|
||||
04DACE8D212CC7CC009840C4 /* AvatarCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarCache.swift; sourceTree = "<group>"; };
|
||||
04ED00B021481ED800567C53 /* SteppedProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SteppedProgressView.swift; sourceTree = "<group>"; };
|
||||
|
@ -232,7 +249,6 @@
|
|||
D646C955213B365700269FB5 /* LargeImageExpandAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageExpandAnimationController.swift; sourceTree = "<group>"; };
|
||||
D646C957213B367000269FB5 /* LargeImageShrinkAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageShrinkAnimationController.swift; sourceTree = "<group>"; };
|
||||
D646C959213B5D0500269FB5 /* LargeImageInteractionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageInteractionController.swift; sourceTree = "<group>"; };
|
||||
D64A0CD22132153900640E3B /* HTMLContentLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTMLContentLabel.swift; sourceTree = "<group>"; };
|
||||
D64D0AAC2128D88B005A6F37 /* LocalData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalData.swift; sourceTree = "<group>"; };
|
||||
D64D0AAE2128D954005A6F37 /* Onboarding.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Onboarding.storyboard; sourceTree = "<group>"; };
|
||||
D64D0AB02128D9AE005A6F37 /* OnboardingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingViewController.swift; sourceTree = "<group>"; };
|
||||
|
@ -254,7 +270,6 @@
|
|||
D667E5E621349D4C0057A976 /* ProfileTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileTableViewController.swift; sourceTree = "<group>"; };
|
||||
D667E5E821349EE50057A976 /* ProfileHeaderTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ProfileHeaderTableViewCell.xib; sourceTree = "<group>"; };
|
||||
D667E5EA21349EF80057A976 /* ProfileHeaderTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileHeaderTableViewCell.swift; sourceTree = "<group>"; };
|
||||
D667E5EE2134C39F0057A976 /* StatusContentLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusContentLabel.swift; sourceTree = "<group>"; };
|
||||
D667E5F02134D5050057A976 /* UIViewController+Delegates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Delegates.swift"; sourceTree = "<group>"; };
|
||||
D667E5F22135BC260057A976 /* Conversation.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Conversation.storyboard; sourceTree = "<group>"; };
|
||||
D667E5F42135BCD50057A976 /* ConversationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationViewController.swift; sourceTree = "<group>"; };
|
||||
|
@ -269,6 +284,7 @@
|
|||
D6C693CC2161257B007D6A6D /* SilentActionPermissionCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SilentActionPermissionCell.xib; sourceTree = "<group>"; };
|
||||
D6C693CE216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SilentActionPermissionTableViewCell.swift; sourceTree = "<group>"; };
|
||||
D6C693EE216192C2007D6A6D /* TuskerNavigationDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TuskerNavigationDelegate.swift; sourceTree = "<group>"; };
|
||||
D6C693F82162E4DB007D6A6D /* StatusContentLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusContentLabel.swift; sourceTree = "<group>"; };
|
||||
D6C94D842139DFD800CB5196 /* LargeImage.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LargeImage.storyboard; sourceTree = "<group>"; };
|
||||
D6C94D862139E62700CB5196 /* LargeImageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeImageViewController.swift; sourceTree = "<group>"; };
|
||||
D6C94D882139E6EC00CB5196 /* AttachmentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentView.swift; sourceTree = "<group>"; };
|
||||
|
@ -292,6 +308,13 @@
|
|||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
04496BC5216252E5001F1B23 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
D61099A82144B0CC00432DC2 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
|
@ -311,6 +334,7 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
04496BCF216252E5001F1B23 /* TTTAttributedLabel.framework in Frameworks */,
|
||||
D61099C02144B0CC00432DC2 /* Pachyderm.framework in Frameworks */,
|
||||
D65A37F321472F300087646E /* SwiftSoup.framework in Frameworks */,
|
||||
);
|
||||
|
@ -333,6 +357,16 @@
|
|||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
04496BC9216252E5001F1B23 /* TTTAttributedLabel */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
04496BCA216252E5001F1B23 /* TTTAttributedLabel.h */,
|
||||
04496BD42162530A001F1B23 /* TTTAttributedLabel.m */,
|
||||
04496BCB216252E5001F1B23 /* Info.plist */,
|
||||
);
|
||||
path = TTTAttributedLabel;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
D61099AC2144B0CC00432DC2 /* Pachyderm */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -606,8 +640,8 @@
|
|||
D6BED1722126661300F02DA0 /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D64A0CD22132153900640E3B /* HTMLContentLabel.swift */,
|
||||
D667E5EE2134C39F0057A976 /* StatusContentLabel.swift */,
|
||||
04496BD621625361001F1B23 /* ContentLabel.swift */,
|
||||
D6C693F82162E4DB007D6A6D /* StatusContentLabel.swift */,
|
||||
D6C94D882139E6EC00CB5196 /* AttachmentView.swift */,
|
||||
D6333B762138D94E00CE884A /* ComposeMediaView.swift */,
|
||||
D641C77E213DC78A004B4513 /* InlineTextAttachment.swift */,
|
||||
|
@ -636,6 +670,7 @@
|
|||
D6BED16E212663DA00F02DA0 /* SwiftSoup.framework */,
|
||||
D61099AC2144B0CC00432DC2 /* Pachyderm */,
|
||||
D61099B92144B0CC00432DC2 /* PachydermTests */,
|
||||
04496BC9216252E5001F1B23 /* TTTAttributedLabel */,
|
||||
D6D4DDCE212518A000E1C4BB /* Tusker */,
|
||||
D6D4DDE3212518A200E1C4BB /* TuskerTests */,
|
||||
D6D4DDEE212518A200E1C4BB /* TuskerUITests */,
|
||||
|
@ -652,6 +687,7 @@
|
|||
D6D4DDEB212518A200E1C4BB /* TuskerUITests.xctest */,
|
||||
D61099AB2144B0CC00432DC2 /* Pachyderm.framework */,
|
||||
D61099B32144B0CC00432DC2 /* PachydermTests.xctest */,
|
||||
04496BC8216252E5001F1B23 /* TTTAttributedLabel.framework */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
|
@ -706,6 +742,14 @@
|
|||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXHeadersBuildPhase section */
|
||||
04496BC3216252E5001F1B23 /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
04496BCC216252E5001F1B23 /* TTTAttributedLabel.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
D61099A62144B0CC00432DC2 /* Headers */ = {
|
||||
isa = PBXHeadersBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
|
@ -717,6 +761,24 @@
|
|||
/* End PBXHeadersBuildPhase section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
04496BC7216252E5001F1B23 /* TTTAttributedLabel */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 04496BD3216252E5001F1B23 /* Build configuration list for PBXNativeTarget "TTTAttributedLabel" */;
|
||||
buildPhases = (
|
||||
04496BC3216252E5001F1B23 /* Headers */,
|
||||
04496BC4216252E5001F1B23 /* Sources */,
|
||||
04496BC5216252E5001F1B23 /* Frameworks */,
|
||||
04496BC6216252E5001F1B23 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = TTTAttributedLabel;
|
||||
productName = TTTAttributedLabel;
|
||||
productReference = 04496BC8216252E5001F1B23 /* TTTAttributedLabel.framework */;
|
||||
productType = "com.apple.product-type.framework";
|
||||
};
|
||||
D61099AA2144B0CC00432DC2 /* Pachyderm */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = D61099C22144B0CC00432DC2 /* Build configuration list for PBXNativeTarget "Pachyderm" */;
|
||||
|
@ -767,6 +829,7 @@
|
|||
);
|
||||
dependencies = (
|
||||
D61099BF2144B0CC00432DC2 /* PBXTargetDependency */,
|
||||
04496BCE216252E5001F1B23 /* PBXTargetDependency */,
|
||||
);
|
||||
name = Tusker;
|
||||
productName = Tusker;
|
||||
|
@ -819,6 +882,9 @@
|
|||
LastUpgradeCheck = 1010;
|
||||
ORGANIZATIONNAME = Shadowfacts;
|
||||
TargetAttributes = {
|
||||
04496BC7216252E5001F1B23 = {
|
||||
CreatedOnToolsVersion = 10.1;
|
||||
};
|
||||
D61099AA2144B0CC00432DC2 = {
|
||||
CreatedOnToolsVersion = 10.0;
|
||||
LastSwiftMigration = 1000;
|
||||
|
@ -858,11 +924,19 @@
|
|||
D6D4DDEA212518A200E1C4BB /* TuskerUITests */,
|
||||
D61099AA2144B0CC00432DC2 /* Pachyderm */,
|
||||
D61099B22144B0CC00432DC2 /* PachydermTests */,
|
||||
04496BC7216252E5001F1B23 /* TTTAttributedLabel */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
04496BC6216252E5001F1B23 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
D61099A92144B0CC00432DC2 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
|
@ -918,6 +992,14 @@
|
|||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
04496BC4216252E5001F1B23 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
04496BD52162530A001F1B23 /* TTTAttributedLabel.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
D61099A72144B0CC00432DC2 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
|
@ -975,6 +1057,7 @@
|
|||
files = (
|
||||
D6757A822157E8FA00721E32 /* XCBSession.swift in Sources */,
|
||||
04DACE8C212CB14B009840C4 /* MainTabBarViewController.swift in Sources */,
|
||||
D6C693F92162E4DB007D6A6D /* StatusContentLabel.swift in Sources */,
|
||||
D667E5F52135BCD50057A976 /* ConversationViewController.swift in Sources */,
|
||||
D6F953F021251A2900CF0F2B /* MastodonController.swift in Sources */,
|
||||
D66362712136338600C9CBA2 /* ComposeViewController.swift in Sources */,
|
||||
|
@ -998,10 +1081,10 @@
|
|||
D6333B792139AEFD00CE884A /* Date+TimeAgo.swift in Sources */,
|
||||
D641C78F213DF2AA004B4513 /* VisibilityTableViewController.swift in Sources */,
|
||||
D641C77F213DC78A004B4513 /* InlineTextAttachment.swift in Sources */,
|
||||
04496BD721625361001F1B23 /* ContentLabel.swift in Sources */,
|
||||
D663626C21361C6700C9CBA2 /* Account+Preferences.swift in Sources */,
|
||||
D6C693CA2161253F007D6A6D /* SilentActionPermissionsTableViewController.swift in Sources */,
|
||||
D6333B372137838300CE884A /* AttributedString+Trim.swift in Sources */,
|
||||
D667E5EF2134C39F0057A976 /* StatusContentLabel.swift in Sources */,
|
||||
D641C777213CAA9E004B4513 /* ActionNotificationTableViewCell.swift in Sources */,
|
||||
D64D0AB12128D9AE005A6F37 /* OnboardingViewController.swift in Sources */,
|
||||
D663626821360E2C00C9CBA2 /* PreferencesTableViewController.swift in Sources */,
|
||||
|
@ -1014,7 +1097,6 @@
|
|||
D641C77D213CB024004B4513 /* FollowNotificationTableViewCell.swift in Sources */,
|
||||
D641C773213CAA25004B4513 /* NotificationsTableViewController.swift in Sources */,
|
||||
D6757A7C2157E01900721E32 /* XCBManager.swift in Sources */,
|
||||
D64A0CD32132153900640E3B /* HTMLContentLabel.swift in Sources */,
|
||||
D6C693CF216125FC007D6A6D /* SilentActionPermissionTableViewCell.swift in Sources */,
|
||||
D6757A7E2157E02600721E32 /* XCBRequestSpec.swift in Sources */,
|
||||
D667E5F12134D5050057A976 /* UIViewController+Delegates.swift in Sources */,
|
||||
|
@ -1043,6 +1125,11 @@
|
|||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXTargetDependency section */
|
||||
04496BCE216252E5001F1B23 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = 04496BC7216252E5001F1B23 /* TTTAttributedLabel */;
|
||||
targetProxy = 04496BCD216252E5001F1B23 /* PBXContainerItemProxy */;
|
||||
};
|
||||
D61099B62144B0CC00432DC2 /* PBXTargetDependency */ = {
|
||||
isa = PBXTargetDependency;
|
||||
target = D61099AA2144B0CC00432DC2 /* Pachyderm */;
|
||||
|
@ -1090,6 +1177,62 @@
|
|||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
04496BD1216252E5001F1B23 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEFINES_MODULE = YES;
|
||||
DEVELOPMENT_TEAM = HGYVAQA9FW;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
INFOPLIST_FILE = TTTAttributedLabel/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
"@loader_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.TTTAttributedLabel;
|
||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
||||
SKIP_INSTALL = YES;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
04496BD2216252E5001F1B23 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEFINES_MODULE = YES;
|
||||
DEVELOPMENT_TEAM = HGYVAQA9FW;
|
||||
DYLIB_COMPATIBILITY_VERSION = 1;
|
||||
DYLIB_CURRENT_VERSION = 1;
|
||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||
INFOPLIST_FILE = TTTAttributedLabel/Info.plist;
|
||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
"@loader_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.shadowfacts.TTTAttributedLabel;
|
||||
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
|
||||
SKIP_INSTALL = YES;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
D61099C32144B0CC00432DC2 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
|
@ -1432,6 +1575,15 @@
|
|||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
04496BD3216252E5001F1B23 /* Build configuration list for PBXNativeTarget "TTTAttributedLabel" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
04496BD1216252E5001F1B23 /* Debug */,
|
||||
04496BD2216252E5001F1B23 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
D61099C22144B0CC00432DC2 /* Build configuration list for PBXNativeTarget "Pachyderm" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
//
|
||||
// ContentLabel.swift
|
||||
// Tusker
|
||||
//
|
||||
// Created by Shadowfacts on 10/1/18.
|
||||
// Copyright © 2018 Shadowfacts. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import TTTAttributedLabel
|
||||
import Pachyderm
|
||||
import SwiftSoup
|
||||
|
||||
protocol ContentLabelNavigationDelegate {
|
||||
func selected(mention: Mention)
|
||||
|
||||
func selected(tag: Hashtag)
|
||||
|
||||
func selected(url: URL)
|
||||
}
|
||||
|
||||
class ContentLabel: TTTAttributedLabel {
|
||||
|
||||
var navigationDelegate: ContentLabelNavigationDelegate?
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
isUserInteractionEnabled = true
|
||||
}
|
||||
|
||||
// MARK: - HTML Parsing
|
||||
func setTextFromHtml(_ html: String) {
|
||||
let doc = try! SwiftSoup.parse(html)
|
||||
let body = doc.body()!
|
||||
|
||||
let (attributedText, links) = attributedTextForHTMLNode(body)
|
||||
let mutAttrString = NSMutableAttributedString(attributedString: attributedText)
|
||||
mutAttrString.trimCharactersInSet(.whitespacesAndNewlines)
|
||||
mutAttrString.addAttribute(.font, value: font, range: NSRange(location: 0, length: mutAttrString.length))
|
||||
self.text = mutAttrString
|
||||
for (range, url) in links {
|
||||
let result = NSTextCheckingResult.linkCheckingResult(range: range, url: url)
|
||||
let link = TTTAttributedLabelLink(attributes: [
|
||||
NSAttributedString.Key.foregroundColor: UIColor.blue
|
||||
], activeAttributes: [
|
||||
kTTTBackgroundFillColorAttributeName: UIColor(displayP3Red: 0.9, green: 0.9, blue: 0.9, alpha: 1),
|
||||
kTTTBackgroundFillPaddingAttributeName: UIEdgeInsets(top: 2, left: 2, bottom: 2, right: 2),
|
||||
kTTTBackgroundCornerRadiusAttributeName: NSNumber(value: 5)
|
||||
], inactiveAttributes: [:], textCheckingResult: result)!
|
||||
link.linkTapBlock = self.linkTapped
|
||||
link.linkLongPressBlock = self.linkLongPressed
|
||||
addLink(link)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func attributedTextForHTMLNode(_ node: Node) -> (NSAttributedString, [NSRange: URL]) {
|
||||
switch node {
|
||||
case let node as TextNode:
|
||||
return (NSAttributedString(string: node.text()), [:])
|
||||
case let node as Element:
|
||||
var links = [NSRange: URL]()
|
||||
let attributed = NSMutableAttributedString()
|
||||
for child in node.getChildNodes() {
|
||||
let (text, childLinks) = attributedTextForHTMLNode(child)
|
||||
for (range, url) in childLinks {
|
||||
let newRange = NSRange(location: range.location + attributed.length, length: range.length)
|
||||
links[newRange] = url
|
||||
}
|
||||
attributed.append(text)
|
||||
}
|
||||
|
||||
switch node.tagName() {
|
||||
case "br":
|
||||
attributed.append(NSAttributedString(string: "\n"))
|
||||
case "a":
|
||||
if let link = try? node.attr("href"),
|
||||
let url = URL(string: link) {
|
||||
let linkRange = NSRange(location: 0, length: attributed.length)
|
||||
links[linkRange] = url
|
||||
}
|
||||
case "p":
|
||||
attributed.append(NSAttributedString(string: "\n\n"))
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
return (attributed, links)
|
||||
default:
|
||||
fatalError("Unexpected node type: \(type(of: node))")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Interaction
|
||||
func linkTapped(_ label: TTTAttributedLabel!, _ link: TTTAttributedLabelLink!) {
|
||||
if let navigationDelegate = navigationDelegate,
|
||||
let url = link.result.url {
|
||||
let text = (self.text as! NSString).substring(with: link.result.range)
|
||||
if let mention = getMention(for: url, text: text) {
|
||||
navigationDelegate.selected(mention: mention)
|
||||
} else if let tag = getHashtag(for: url, text: text) {
|
||||
navigationDelegate.selected(tag: tag)
|
||||
} else {
|
||||
navigationDelegate.selected(url: url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func linkLongPressed(_ label: TTTAttributedLabel!, _ link: TTTAttributedLabelLink!) {
|
||||
// todo: long press options
|
||||
}
|
||||
|
||||
// MARK: - Navigation
|
||||
func getMention(for url: URL, text: String) -> Mention? {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getHashtag(for url: URL, text: String) -> Hashtag? {
|
||||
if text.starts(with: "#") {
|
||||
let tag = String(text.dropFirst())
|
||||
return Hashtag(name: tag, url: url)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,305 +0,0 @@
|
|||
//
|
||||
// StatusContentLabel.swift
|
||||
// Tusker
|
||||
//
|
||||
// Created by Shadowfacts on 8/25/18.
|
||||
// Copyright © 2018 Shadowfacts. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Pachyderm
|
||||
import SwiftSoup
|
||||
|
||||
protocol HTMLContentLabelDelegate {
|
||||
|
||||
func selected(mention: Mention)
|
||||
|
||||
func selected(tag: Hashtag)
|
||||
|
||||
func selected(url: URL)
|
||||
|
||||
}
|
||||
|
||||
class HTMLContentLabel: UILabel {
|
||||
|
||||
var delegate: HTMLContentLabelDelegate?
|
||||
|
||||
override var text: String? {
|
||||
didSet {
|
||||
parseHTML()
|
||||
}
|
||||
}
|
||||
|
||||
override var attributedText: NSAttributedString? {
|
||||
didSet {
|
||||
updateTextStorage()
|
||||
}
|
||||
}
|
||||
|
||||
override var numberOfLines: Int {
|
||||
didSet {
|
||||
textContainer.maximumNumberOfLines = numberOfLines
|
||||
}
|
||||
}
|
||||
|
||||
override var lineBreakMode: NSLineBreakMode {
|
||||
didSet {
|
||||
textContainer.lineBreakMode = lineBreakMode
|
||||
}
|
||||
}
|
||||
|
||||
// var status: Status! {
|
||||
// didSet {
|
||||
// text = status.content
|
||||
// }
|
||||
// }
|
||||
|
||||
private var _customizing = true
|
||||
|
||||
private lazy var textStorage = NSTextStorage()
|
||||
private lazy var layoutManager = NSLayoutManager()
|
||||
private lazy var textContainer = NSTextContainer()
|
||||
|
||||
private var selectedLink: (range: NSRange, url: URL)?
|
||||
|
||||
private var links: [NSRange: URL] = [:]
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
_customizing = false
|
||||
setupLabel()
|
||||
}
|
||||
|
||||
required init?(coder aDecoder: NSCoder) {
|
||||
super.init(coder: aDecoder)
|
||||
_customizing = false
|
||||
setupLabel()
|
||||
}
|
||||
|
||||
private func setupLabel() {
|
||||
textStorage.addLayoutManager(layoutManager)
|
||||
layoutManager.addTextContainer(textContainer)
|
||||
textContainer.lineFragmentPadding = 0
|
||||
textContainer.lineBreakMode = lineBreakMode
|
||||
textContainer.maximumNumberOfLines = numberOfLines
|
||||
isUserInteractionEnabled = true
|
||||
}
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
updateTextStorage()
|
||||
}
|
||||
|
||||
override var intrinsicContentSize: CGSize {
|
||||
let superSize = super.intrinsicContentSize
|
||||
textContainer.size = CGSize(width: superSize.width, height: .greatestFiniteMagnitude)
|
||||
let size = layoutManager.usedRect(for: textContainer)
|
||||
return CGSize(width: ceil(size.width), height: ceil(size.height))
|
||||
}
|
||||
|
||||
override func drawText(in rect: CGRect) {
|
||||
let range = NSRange(location: 0, length: textStorage.length)
|
||||
|
||||
textContainer.size = rect.size
|
||||
let origin = rect.origin
|
||||
|
||||
layoutManager.drawBackground(forGlyphRange: range, at: origin)
|
||||
layoutManager.drawGlyphs(forGlyphRange: range, at: origin)
|
||||
}
|
||||
|
||||
// MARK: - HTML parsing
|
||||
|
||||
private func parseHTML() {
|
||||
if _customizing { return }
|
||||
guard let text = text else { return }
|
||||
|
||||
let doc = try! SwiftSoup.parse(text)
|
||||
let body = doc.body()!
|
||||
|
||||
let (attributedText, links) = attributedTextForHTMLNode(body)
|
||||
self.links = links
|
||||
let mutAttrString = NSMutableAttributedString(attributedString: attributedText)
|
||||
mutAttrString.trimCharactersInSet(.whitespacesAndNewlines)
|
||||
mutAttrString.addAttribute(.font, value: font, range: NSRange(location: 0, length: mutAttrString.length))
|
||||
self.attributedText = mutAttrString
|
||||
}
|
||||
|
||||
private func attributedTextForHTMLNode(_ node: Node) -> (NSAttributedString, [NSRange: URL]) {
|
||||
switch node {
|
||||
case let node as TextNode:
|
||||
return (NSAttributedString(string: node.text()), [:])
|
||||
case let node as Element:
|
||||
var links = [NSRange: URL]()
|
||||
let attributed = NSMutableAttributedString()
|
||||
node.getChildNodes().forEach { child in
|
||||
let (text, childLinks) = attributedTextForHTMLNode(child)
|
||||
childLinks.forEach { range, url in
|
||||
let newRange = NSRange(location: range.location + attributed.length, length: range.length)
|
||||
links[newRange] = url
|
||||
}
|
||||
attributed.append(text)
|
||||
}
|
||||
|
||||
switch node.tagName() {
|
||||
case "br":
|
||||
attributed.append(NSAttributedString(string: "\n"))
|
||||
case "a":
|
||||
if let link = try? node.attr("href"),
|
||||
let url = URL(string: link) {
|
||||
let linkRange = NSRange(location: 0, length: attributed.length)
|
||||
let linkAttributes: [NSAttributedString.Key: Any] = [
|
||||
.foregroundColor: UIColor.blue
|
||||
]
|
||||
attributed.setAttributes(linkAttributes, range: linkRange)
|
||||
|
||||
links[linkRange] = url
|
||||
}
|
||||
case "p":
|
||||
attributed.append(NSAttributedString(string: "\n\n"))
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
||||
return (attributed, links)
|
||||
default:
|
||||
fatalError("Unexpected node type: \(type(of: node))")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Text Storage
|
||||
|
||||
private func updateTextStorage() {
|
||||
if _customizing { return }
|
||||
guard let attributedText = attributedText,
|
||||
attributedText.length > 0 else {
|
||||
links = [:]
|
||||
textStorage.setAttributedString(NSAttributedString())
|
||||
setNeedsDisplay()
|
||||
return
|
||||
}
|
||||
|
||||
textStorage.setAttributedString(attributedText)
|
||||
_customizing = true
|
||||
text = attributedText.string
|
||||
_customizing = false
|
||||
setNeedsDisplay()
|
||||
}
|
||||
|
||||
// MARK: - Interaction
|
||||
|
||||
func getMention(for url: URL, text: String) -> Mention? {
|
||||
// todo: figure out how to get account IDs
|
||||
return nil
|
||||
}
|
||||
|
||||
func getTag(for url: URL, text: String) -> Hashtag? {
|
||||
if text.starts(with: "#") {
|
||||
let tag = String(text.dropFirst())
|
||||
return Hashtag(name: tag, url: url)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
private func onTouch(_ touch: UITouch) -> Bool {
|
||||
let location = touch.location(in: self)
|
||||
var avoidSuperCall = false
|
||||
|
||||
switch touch.phase {
|
||||
case .began, .moved:
|
||||
if let link = link(at: location) {
|
||||
if link.range.location != selectedLink?.range.location || link.range.length != selectedLink?.range.length {
|
||||
updateAttributesWhenSelected(false)
|
||||
selectedLink = link
|
||||
updateAttributesWhenSelected(true)
|
||||
}
|
||||
avoidSuperCall = true
|
||||
} else {
|
||||
updateAttributesWhenSelected(false)
|
||||
selectedLink = nil
|
||||
}
|
||||
case .ended:
|
||||
guard let selectedLink = selectedLink else { return avoidSuperCall }
|
||||
|
||||
let text = String(self.text![Range(selectedLink.range, in: self.text!)!])
|
||||
if let delegate = delegate {
|
||||
if let mention = getMention(for: selectedLink.url, text: text) {
|
||||
delegate.selected(mention: mention)
|
||||
} else if let tag = getTag(for: selectedLink.url, text: text) {
|
||||
delegate.selected(tag: tag)
|
||||
} else {
|
||||
delegate.selected(url: selectedLink.url)
|
||||
}
|
||||
}
|
||||
|
||||
let when = DispatchTime.now() + Double(Int64(0.25 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
|
||||
DispatchQueue.main.asyncAfter(deadline: when) {
|
||||
self.updateAttributesWhenSelected(false)
|
||||
self.selectedLink = nil
|
||||
}
|
||||
case .cancelled:
|
||||
updateAttributesWhenSelected(false)
|
||||
selectedLink = nil
|
||||
case .stationary:
|
||||
break
|
||||
}
|
||||
|
||||
return avoidSuperCall
|
||||
}
|
||||
|
||||
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
guard let touch = touches.first else { return }
|
||||
if onTouch(touch) { return }
|
||||
super.touchesBegan(touches, with: event)
|
||||
}
|
||||
|
||||
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
guard let touch = touches.first else { return }
|
||||
if onTouch(touch) { return }
|
||||
super.touchesMoved(touches, with: event)
|
||||
}
|
||||
|
||||
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
guard let touch = touches.first else { return }
|
||||
if onTouch(touch) { return }
|
||||
super.touchesCancelled(touches, with: event)
|
||||
}
|
||||
|
||||
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
guard let touch = touches.first else { return }
|
||||
if onTouch(touch) { return }
|
||||
super.touchesEnded(touches, with: event)
|
||||
}
|
||||
|
||||
private func link(at location: CGPoint) -> (range: NSRange, url: URL)? {
|
||||
guard textStorage.length > 0 else { return nil }
|
||||
|
||||
let boundingRect = layoutManager.boundingRect(forGlyphRange: NSRange(location: 0, length: textStorage.length), in: textContainer)
|
||||
guard boundingRect.contains(location) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let index = layoutManager.glyphIndex(for: location, in: textContainer)
|
||||
|
||||
for (range, url) in links {
|
||||
if index >= range.location && index <= range.location + range.length {
|
||||
return (range, url)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
private func updateAttributesWhenSelected(_ isSelected: Bool) {
|
||||
guard let selectedLink = selectedLink else { return }
|
||||
|
||||
var attributes = textStorage.attributes(at: 0, effectiveRange: nil)
|
||||
|
||||
attributes[.foregroundColor] = isSelected ? nil : UIColor.blue
|
||||
|
||||
textStorage.addAttributes(attributes, range: selectedLink.range)
|
||||
|
||||
setNeedsDisplay()
|
||||
}
|
||||
|
||||
}
|
|
@ -40,7 +40,7 @@ class ActionNotificationTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
actionAvatarImageView.layer.masksToBounds = true
|
||||
actionLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(actionPressed)))
|
||||
actionLabel.isUserInteractionEnabled = true
|
||||
contentLabel.delegate = self
|
||||
contentLabel.navigationDelegate = self
|
||||
}
|
||||
|
||||
func updateUIForPreferences() {
|
||||
|
@ -129,7 +129,8 @@ class ActionNotificationTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
attachmentsView.isHidden = true
|
||||
}
|
||||
|
||||
contentLabel.statusID = status.id
|
||||
// contentLabel.statusID = status.id
|
||||
contentLabel.setTextFromHtml(status.content)
|
||||
}
|
||||
|
||||
func updateTimestamp() {
|
||||
|
@ -185,18 +186,16 @@ class ActionNotificationTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
|
||||
}
|
||||
|
||||
extension ActionNotificationTableViewCell: HTMLContentLabelDelegate {
|
||||
|
||||
extension ActionNotificationTableViewCell: ContentLabelNavigationDelegate {
|
||||
func selected(mention: Mention) {
|
||||
delegate?.selected(mention: mention)
|
||||
}
|
||||
|
||||
|
||||
func selected(tag: Hashtag) {
|
||||
delegate?.selected(tag: tag)
|
||||
}
|
||||
|
||||
|
||||
func selected(url: URL) {
|
||||
delegate?.selected(url: url)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
@IBOutlet weak var displayNameLabel: UILabel!
|
||||
@IBOutlet weak var usernameLabel: UILabel!
|
||||
@IBOutlet weak var followsYouLabel: UILabel!
|
||||
@IBOutlet weak var noteLabel: HTMLContentLabel!
|
||||
@IBOutlet weak var noteLabel: StatusContentLabel!
|
||||
|
||||
var accountID: String!
|
||||
|
||||
|
@ -38,6 +38,7 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
avatarImageView.isUserInteractionEnabled = true
|
||||
headerImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(headerPressed)))
|
||||
headerImageView.isUserInteractionEnabled = true
|
||||
noteLabel.navigationDelegate = self
|
||||
}
|
||||
|
||||
func updateUIForPreferences() {
|
||||
|
@ -73,9 +74,7 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
}
|
||||
headerImageDownloadTask!.resume()
|
||||
|
||||
// todo: HTML parsing
|
||||
noteLabel.text = account.note
|
||||
noteLabel.delegate = self
|
||||
noteLabel.setTextFromHtml(account.note)
|
||||
|
||||
if let relationship = MastodonCache.relationship(for: accountID) {
|
||||
followsYouLabel.isHidden = !relationship.followedBy
|
||||
|
@ -108,8 +107,7 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
|
||||
}
|
||||
|
||||
extension ProfileHeaderTableViewCell: HTMLContentLabelDelegate {
|
||||
|
||||
extension ProfileHeaderTableViewCell: ContentLabelNavigationDelegate {
|
||||
func selected(mention: Mention) {
|
||||
delegate?.selected(mention: mention)
|
||||
}
|
||||
|
@ -121,5 +119,4 @@ extension ProfileHeaderTableViewCell: HTMLContentLabelDelegate {
|
|||
func selected(url: URL) {
|
||||
delegate?.selected(url: url)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Note" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="I0n-aP-dJP" customClass="HTMLContentLabel" customModule="Tusker" customModuleProvider="target">
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="Note" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="I0n-aP-dJP" customClass="StatusContentLabel" customModule="Tusker" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="37" height="70"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
|
|
|
@ -49,7 +49,7 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive
|
|||
avatarImageView.layer.masksToBounds = true
|
||||
attachmentsView.layer.cornerRadius = 5
|
||||
attachmentsView.layer.masksToBounds = true
|
||||
contentLabel.delegate = self
|
||||
contentLabel.navigationDelegate = self
|
||||
}
|
||||
|
||||
func updateUIForPreferences() {
|
||||
|
@ -218,8 +218,7 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive
|
|||
|
||||
}
|
||||
|
||||
extension ConversationMainStatusTableViewCell: HTMLContentLabelDelegate {
|
||||
|
||||
extension ConversationMainStatusTableViewCell: ContentLabelNavigationDelegate {
|
||||
func selected(mention: Mention) {
|
||||
delegate?.selected(mention: mention)
|
||||
}
|
||||
|
@ -231,7 +230,6 @@ extension ConversationMainStatusTableViewCell: HTMLContentLabelDelegate {
|
|||
func selected(url: URL) {
|
||||
delegate?.selected(url: url)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension ConversationMainStatusTableViewCell: AttachmentViewDelegate {
|
||||
|
|
|
@ -57,7 +57,7 @@ class StatusTableViewCell: UITableViewCell, PreferencesAdaptive {
|
|||
avatarImageView.layer.masksToBounds = true
|
||||
attachmentsView.layer.cornerRadius = 5
|
||||
attachmentsView.layer.masksToBounds = true
|
||||
contentLabel.delegate = self
|
||||
contentLabel.navigationDelegate = self
|
||||
}
|
||||
|
||||
func updateUIForPreferences() {
|
||||
|
@ -346,11 +346,9 @@ extension StatusTableViewCell: TableViewSwipeActionProvider {
|
|||
return UISwipeActionsConfiguration(actions: [reply, more])
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension StatusTableViewCell: HTMLContentLabelDelegate {
|
||||
|
||||
extension StatusTableViewCell: ContentLabelNavigationDelegate {
|
||||
func selected(mention: Mention) {
|
||||
delegate?.selected(mention: mention)
|
||||
}
|
||||
|
@ -362,7 +360,6 @@ extension StatusTableViewCell: HTMLContentLabelDelegate {
|
|||
func selected(url: URL) {
|
||||
delegate?.selected(url: url)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension StatusTableViewCell: AttachmentViewDelegate {
|
||||
|
|
|
@ -2,36 +2,48 @@
|
|||
// StatusContentLabel.swift
|
||||
// Tusker
|
||||
//
|
||||
// Created by Shadowfacts on 8/27/18.
|
||||
// Created by Shadowfacts on 10/1/18.
|
||||
// Copyright © 2018 Shadowfacts. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Pachyderm
|
||||
|
||||
class StatusContentLabel: HTMLContentLabel {
|
||||
class StatusContentLabel: ContentLabel {
|
||||
|
||||
var statusID: String! {
|
||||
var statusID: String? {
|
||||
didSet {
|
||||
text = status.content
|
||||
guard let statusID = statusID else { return }
|
||||
guard let status = MastodonCache.status(for: statusID) else { fatalError("Can't set StatusContentLabel text without cached status \(statusID)") }
|
||||
setTextFromHtml(status.content)
|
||||
}
|
||||
}
|
||||
var status: Status! {
|
||||
return MastodonCache.status(for: statusID)
|
||||
}
|
||||
|
||||
override func getMention(for url: URL, text: String) -> Mention? {
|
||||
return status.mentions.first(where: { mention -> Bool in
|
||||
(text.dropFirst() == mention.username || text == mention.username) && url.host == mention.url.host
|
||||
}) ?? super.getMention(for: url, text: text)
|
||||
let mention: Mention?
|
||||
if let statusID = statusID,
|
||||
let status = MastodonCache.status(for: statusID) {
|
||||
mention = status.mentions.first { (mention) in
|
||||
// Mastodon and Pleroma include the @ in the <a> text, GNU Social does not
|
||||
(text.dropFirst() == mention.username || text == mention.username) && url.host == mention.url.host
|
||||
}
|
||||
} else {
|
||||
mention = nil
|
||||
}
|
||||
return mention ?? super.getMention(for: url, text: text)
|
||||
}
|
||||
|
||||
override func getTag(for url: URL, text: String) -> Hashtag? {
|
||||
if let tag = status.hashtags.first(where: { $0.url == url }) {
|
||||
return tag
|
||||
override func getHashtag(for url: URL, text: String) -> Hashtag? {
|
||||
let hashtag: Hashtag?
|
||||
if let statusID = statusID,
|
||||
let status = MastodonCache.status(for: statusID) {
|
||||
hashtag = status.hashtags.first { (hashtag) in
|
||||
hashtag.url == url
|
||||
}
|
||||
} else {
|
||||
return super.getTag(for: url, text: text)
|
||||
hashtag = nil
|
||||
}
|
||||
return hashtag ?? super.getHashtag(for: url, text: text)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue