Giter VIP home page Giter VIP logo

dbfbprofilepictureview's Introduction

DBFBProfilePictureView - an improved view for facebook profile pictures

There were a number of things I wanted to fix with the Facebook provided FBProfilePictureView:

  • Caching of the downloaded profile images, so the network did not get hit for every instance of the view
  • Start and completion handlers to allow control of the presentation of the view (e.g. fade-in or show a UIActivityIndicatorView)
  • Be notified when the download fails
  • Control of when the empty profile image got shown
  • Work well when the view is embedded in a UITableCellView

In addition there are a couple of other significant changes:

  • The implementation has been converted to ARC
  • key/value observing is used to monitor changes to profileID and pictureCropping
  • no download request is made for zero size images

Installation

The simplest way to install DBFBProfilePictureView is to use CocoaPods. The homepage has a quick start guide. Add the following to your Podfile:

	platform :ios, '5.0'
	pod 'DBFBProfilePictureView', '1.1.0'

This will then automatically handle the dependencies. Also, it is a simple way to get updates.

If you want to take the manual approach then the two files needed are in the sub-directory DBFBProfilePictureView. To build them you will also need AFNetworking 1.0 or later and the Facebook iOS SDK v3.1.1. Either your project needs to be built with ARC enabled, or you will need to set the -fobjc-arc flag as described here.

Getting Started

A typical usage of the view might look like this...

Declare the property in a view controller or UITableCellView:

    @property(strong) DBFBProfilePictureView* facebookPictureView;

Import QuartzCore as we will be using CALayer:

    #import <QuartzCore/QuartzCore.h>

Initialize the property in viewDidLoad of your view controller or init of your UITableCellView:

        self.facebookPictureView = [[DBFBProfilePictureView alloc] initWithFrame:CGRectMake(x,y,width,height)];
        //hide the view when the download starts
        self.facebookPictureView.startHandler = ^(DBFBProfilePictureView* view){
            view.layer.opacity = 0.0f;
        };
        //show the view when the download completes, or show the empty image
        self.facebookPictureView.completionHandler = ^(DBFBProfilePictureView* view, NSError* error){
            if(error) {
                view.showEmptyImage = YES;
                view.profileID = nil;
                NSLog(@"Loading profile picture failed with error: %@", error);
            } 
            [UIView animateWithDuration:0.5f animations:^{
                view.layer.opacity = 1.0f;
            }];
        };

Set the profileID when you know it:

		facebookPictureView.profileID = xxxxx;

Version history

1.0.0 - Initial release 1.1.0 - Add in-memory caching & sharing of UIImage objects for the same requested URL

License

Licensed under Apache License, Version 2.0

dbfbprofilepictureview's People

Contributors

combinatorial avatar

Watchers

kevin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.