Inherits from UIView
Conforms to UIAppearanceContainer
Declared in TWTRTweetView.h

Overview

TWTRTweetView displays a single Tweet to the user. It handles background taps and other actions displayed to the user.

TWTRAPIClient *APIClient = [[TWTRAPIClient alloc] init];
[[APIClient loadTweetWithID:@"20" completion:^(TWTRTweet *tweet, NSError *error) {
    if (tweet) {
        TWTRTweetView *tweetView = [[TWTRTweetView alloc] initWithTweet:tweet];
        [self.view addSubview:tweetView];
    } else {
        NSLog(@"Error loading Tweet: %@", [error localizedDescription]);
    }
}];

Interaction

The TWTRTweetViewDelegate is notified:

  • When the background is tapped.
  • When a link is selected.
  • When the share button is tapped.
  • When the share action completes.
  • When the favorite action completes.

Usage in UITableView

To allow for usage in a UITableView, the configureWithTweet: method allows configuration of an existing TWTRTweetView without having to create a new instance.

Sizing

When using Auto Layout, feel free to set a width or margin on the Tweet view. The height will be calculated automatically. For old-fashioned frame based layout you may use the standard sizeThatFits: method to calculate the appropriate height for a given width:

// Find the height for a given width (20pts on either side)
CGFloat desiredHeight = [tweetView sizeThatFits:CGSizeMake(self.view.frame.size.width - 40, CGFLOAT_MAX)].height;

UIAppearance

You may use UIAppearance proxy objects to style certain aspects of Tweet views before those views are added to the view hierarchy.

 // Using UIAppearance Proxy
 [TWTRTweetView appearance].theme = TWTRTweetViewThemeDark;

 // Setting colors directly
 [TWTRTweetView appearance].primaryTextColor = [UIColor yellowColor];
 [TWTRTweetView appearance].backgroundColor = [UIColor blueColor];

 // Setting action button visibility
 [TWTRTweetView appearance].showActionButtons = NO;

Note: You can’t change the theme through an appearance proxy after the view has already been added to the view hierarchy. Direct theme property access will work though.

Properties

backgroundColor

Background color of the Tweet view and all text labels (fullname, username, Tweet text, timestamp).

@property (nonatomic) UIColor *backgroundColor

Declared In

TWTRTweetView.h

delegate

Optional delegate to receive notifications when certain actions happen

@property (nonatomic, weak) IBOutlet id<TWTRTweetViewDelegate> delegate

Declared In

TWTRTweetView.h

linkTextColor

Color of links in Tweet text.

@property (nonatomic) UIColor *linkTextColor

Declared In

TWTRTweetView.h

presenterViewController

Optional property to set a UIViewController from which to present various new UI e.g. when presenting a Share sheet, presenting a login view controller for actions, etc

@property (nonatomic, weak) UIViewController *presenterViewController

Declared In

TWTRTweetView.h

primaryTextColor

Color of Tweet text and full name.

@property (nonatomic) UIColor *primaryTextColor

Declared In

TWTRTweetView.h

showActionButtons

Set whether the action buttons (Favorite, Share) should be shown. When toggled, both the visibility of the action buttons and the internal constraints are updated immediately. The layout will be updated the next layout pass that occurs.

@property (nonatomic) BOOL showActionButtons

Discussion

Defaults to NO.

Declared In

TWTRTweetView.h

showBorder

Set whether the border should be shown. Defaults to YES.

@property (nonatomic) BOOL showBorder

Declared In

TWTRTweetView.h

style

The style of the Tweet. i.e. TWTRTweetViewStyleRegular or TWTRTweetViewStyleCompact.

@property (nonatomic, readonly) TWTRTweetViewStyle style

Declared In

TWTRTweetView.h

theme

Setting the theme of the Tweet view will change the color properties accordingly.

@property (nonatomic) TWTRTweetViewTheme theme

Discussion

Set to TWTRTweetViewThemeLight by default.

Declared In

TWTRTweetView.h

tweet

The Tweet being displayed.

@property (nonatomic, readonly) TWTRTweet *tweet

Declared In

TWTRTweetView.h

Instance Methods

configureWithTweet:

Update all images and label text to fully represent the given Tweet.

- (void)configureWithTweet:(nullable TWTRTweet *)tweet

Parameters

tweet

The Tweet to display.

Declared In

TWTRTweetView.h

initWithFrame:

Initialization with a frame parameter is not supported.

- (instancetype)initWithFrame:(CGRect)frame

Declared In

TWTRTweetView.h

initWithTweet:

Convenience initializer to configure a compact style Tweet view.

- (instancetype)initWithTweet:(nullable TWTRTweet *)tweet

Parameters

tweet

The Tweet to display.

Return Value

The fully-configured Tweet view.

Declared In

TWTRTweetView.h

initWithTweet:style:

Designated initializer. Initializes view with both Tweet and style.

- (instancetype)initWithTweet:(nullable TWTRTweet *)tweet style:(TWTRTweetViewStyle)style

Parameters

tweet

The Tweet to display.

style

The style of the Tweet view (regular or compact).

Return Value

The fully configured Tweet view.

Declared In

TWTRTweetView.h

sizeThatFits:

Find the size that fits into a desired space. This is a system method on UIView but implemented on TWTRTweetView

- (CGSize)sizeThatFits:(CGSize)size

Parameters

size

The space available. Should generally leave one orientation unconstrained, and the minimum width supported is 200pts.

Return Value

The size that will fit into the space available.

Discussion

// Calculate the desired height at 280 points wide
CGSize desiredSize = [tweetView sizeThatFits:CGSizeMake(280, CGFLOAT_MAX)];

Declared In

TWTRTweetView.h