In the last article we demonstrated how to take a picture using your iPhone camera and also how to apply filters to the new image using the Core Image API. In this article we are going to allow the user to share the image on Twitter by using the Twitter API provided in the iOS 5 framework.

Interface Changes:

We did a little bit of interface cleanup since we needed to add additional controls to share the picture. We dynamically created the filters using UIScrollView control and added it on the view. We also added a UIToolbar control at the bottom which will allow the user share the picture using the Twitter account.

The screenshot below shows the new interface in action:



As you can see we have added the UIToolbar in the bottom which consists of the Tweet button. You will also notice that there is a highlight effect on the preview filter image when you select it. In the next few sections we are going to learn how to implement the highlight effect and also how to share the picture on Twitter.

Implementing the Highlight Effect:

First we expose the selected filter view by using a new instance variable named selectedFilterView as implemented in the code below:



In the applyFilter method we created the highlight effect which is applied on the selected filter. The implementation is shown below:



We have utilized the view’s layer property to change the shadow, opacity and offset.

The effect is shown in the screenshot below:



Going Social:

After you have taken the picture and applied awesome effects to it you will want to share it with the rest of the world. In iOS 5 Apple introduced the Twiiter library which easily allow to integrate your app with the Twitter social networking platform. First, make sure that the Twitter framework is added in your application as shown in the screenshot below:



Next, implement the code for the Tweet button which will bring up the Tweet window. The code is shown below:



First we check and make sure that the app is able to send tweets. This is performed by using the canSendTweet method of the TWTweetComposeViewController class. The canSendTweet will return false if the twitter account is not correctly configured. If you are running it on the simulator then go to the settings and configure the Twitter account correctly. Take a look at the screenshot below to have a better idea:



Once the Twitter account is established correctly, sending a tweet is only a matter of 3-4 lines as shown in the above implementation. The screenshot below shows the Twitter feature in action:



Conclusion:

In this article we learned how to apply the highlight effect on the selected preview image. We also learned how to be social by sharing the pictures on Twitter.