Browse Month: September 2012

How to keep original orientation of the UIImage..

Hello All,

While working on an application, I was having the client’s requirement that, while displaying an image in imageview the image must be of same orientation same as the original.

After googling, I got the way for doing this.

Here is the way,

UIImage *image; //Here assign the image which you want

UIImageView *imageView = [[UIImageView alloc] init];

imageView.image = image;

imageView.contentMode = UIViewContentModeScaleAspectFit;

Setting this property gives the original orientation of the image.

So simple…

Happy Coding…. 🙂


Showing a Popover in iPad

The UIPopoverController class (for iPad) is a very neat way to present information to the user. In this blog, we’ll show how to use this class to present a popover view when the user touches a button. Let’s see how it works.

Start Xcode, click on “Create a new Xcode project,” and select the Single View Application template. Name the project PopoverDemo, and choose options as shown here:

Click Next, choose a location to save the project, and click Create.

We now have a single view application. Open ViewController.xib, and drag a UIButton to the view. Change its title to “Show Popover…” and also choose a color for the background of the view. When finished, the xib should look something like this:

In ViewController.h, make the following changes:

#import <UIKit/UIKit.h>
#import “PopoverViewController.h” 

@interface ViewController : UIViewController

@property (nonatomic, strong) IBOutlet UIButton *btnShowPopover;

– (IBAction)showPopover:(UIButton *)sender;


Notice that we’ve imported a view controller that does not yet exist: we’ll take care of that soon. We’ve also added an IBOutlet property for the button, as well as an action method. Wire up the property and method (in the ViewController.xib file) as shown:

We will now make a new view controller for our popover. In the navigator panel, select ViewController.xib, then right – click, and choose “New File…” Select the Objective-C Class template, click Next, name the new class PopoverViewController, and make sure that it is a subclass of UIViewController as shown:

Click Next, save the class in the default location, and click Create.

Now open PopoverViewController.xib, select the view, and delete it. (You cannot resize a view made by Xcode as a part of the view controller creation process.) Drag a new UIView from the library, and in the Size inspector, set the view’s properties as shown:

(The value of Height will not be used, the height of the popover will be configured by the system when it is displayed.)

Drag a Navigation Bar to the top of the view; also drag a UILabel onto the view. Set their texts as shown:

In this demo, we’ve also set the background color for the view. Now right – click the File’s Owner object, and drag from the circle to the right of “view” to the new View we’ve just created. This sets the View in interface builder as the PopoverViewController’s view property. (If we omit this step, the view controller cannot display the view!)

Open ViewController.m, and alter the file as shown:

#import “ViewController.h” 

@interface ViewController ()
PopoverViewController *controller;
UIPopoverController *popoverController;


@implementation ViewController

@synthesize btnShowPopover;

– (IBAction)showPopover:(UIButton *)sender
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
} else {
//the rectangle here is the frame of the object that presents the popover,
//in this case, the UIButton…
CGRect popRect = CGRectMake(self.btnShowPopover.frame.origin.x,
[popoverController presentPopoverFromRect:popRect

– (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
controller = [[PopoverViewController alloc]initWithNibName:@”PopoverViewController” bundle:nil];
popoverController = [[UIPopoverController alloc]initWithContentViewController:controller];

– (void)viewDidUnload
[super viewDidUnload];
// Release any retained subviews of the main view.

return YES;


Notice that the PopoverViewController (controller) and UIPopoverController (popoverController) objects are declared as iVars in the @interface section of the .m file, rather than properties. These iVars will not be exposed to any other class, nor should they be: they are private to the implementation of ViewController.

Let’s look first at viewDidLoad:. In this method, we instantiate both controller and popoverController. The controller object is an instance of our PopoverViewController class, we initialize it here with the nib name of the xib file, though initializing it with a nib name of nil would work as well. (Why? See the end of the blog for the answer…) After the controller is instantiated, we initialize popoverController with its contentViewController property set to the controller object.

In the showPopover: method, we respond to a touch on the button. If the popoverController is already shown, it is dismissed. Otherwise, we call presentPopoverFromRect: inView: permittedArrowDirections: animated:. The rectangle to use here is the frame of the object that summons the popover; in this case, the frame of the UIButton object. (This is the reason we set an outlet property to the button.) It is a good idea to use UIPopoverArrowDirectionAny as the value of the permittedArrowDirections argument: this ensures that wherever the system displays the popover, its arrow will always point to the control that summoned it.

In this demo, we’re not making any changes to the PopoverViewController class. We could place a button in the PopoverViewController.xib that calls a delegate method back to ViewController to dismiss the popover, but in this case, we simply rely on the fact that when the user touches outside the popover, it will be dismissed.

Run the application in both portrait and landscape mode:

There is nothing in our code that sets the behavior of the popover, except passing it the information about the button’s frame. In any orientation, the arrow of the popover will always point to the button, and the popover’s height and position will be adjusted to the best fit.


Memory Management in iPhone applications


Recently, I came to an issue of memory leakage while developing an application. And that was the frustrating experience. And it taught a big lesson.

Every time I was running application on device, it was crashing the app after some memory warning.

It was the indication that my application was utilizing lot of memory.

In my code, I had allocated lot of arrays but had not released them after their use ends.

Then I realized that memory management is the most important part of the application development.

There is one more way, instead of using lot of arrays we can use an NSObject class with required properties for entities. This makes the code handy and clean. Also this will help us to avoid memory warnings.

Development of an application always needs best memory management to keep running the application smoothly.

Hope this will help you guys..

Have Happy Coding … !!!@@@

Shaking Animation of an UIView


Hello friends,

Here we will learn how to add shaking animation to an UIView.

It’s just an CABasicAnimation,

CABasicAnimation* anim = [CABasicAnimation animationWithKeyPath:@”transform.rotation”];

[anim setToValue:[NSNumber numberWithFloat:0.0f]];

[anim setFromValue:[NSNumber numberWithDouble:M_PI/30]]; // rotation angle

[anim setDuration:0.1];

[anim setRepeatCount:NSUIntegerMax];

[anim setAutoreverses:YES];

[pressedImageView.layer addAnimation:anim forKey:@”iconShake”];

In above code, pressedImageView is an UIImageview. This animation can be added to other UIView elements too.

You can adjust the rotation angle, by setting the proper value.

Hope this will be helpful  to somebody.

Happy Coding…!!

How to merge two UIImages programmatically?

Hi all,

While developing an application I came to this issue. I was suppose to merge 2 images programmatically.

I googled a little bit and found a function, then I modified it as follows for my requirements

-(UIImage *) mergeTwoImages: (UIImage *)bottomImage : (UIImage *)upperImage : (CGRect)rect


UIImage *image = upperImage;

CGSize newSize = CGSizeMake(bottomImage.size.width, bottomImage.size.height);

UIGraphicsBeginImageContext( newSize );

// Use existing opacity as is

[bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

// Apply supplied opacity

[image drawInRect:rect blendMode:kCGBlendModeNormal alpha:1.0];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();


return newImage;


We just need to pass both the images to be merged and also the co ordinates of the upper image.

That’s it!

Happy Coding 🙂

How to send email through salesforce apex?


Class Code:

public class clsTest
public Boolean emailSent { get; set; }
public void sendMail(string email){

Messaging.SingleEmailMessage mailHandler = new Messaging.SingleEmailMessage();

String[] emailRecipient = new String[]{email};
//set the recipient

//set the reply email address

//set the display name

//set the subject

//set the template ID


Messaging.sendEmail(new Messaging.Email[] { mailHandler });
emailSent = true;
catch(EmailException e)
emailSent = false;


Page Code:

<apex:page controller="clsTest" action="{!sendMail}" title="Email Sending">
   <apex:outputText value="{!emailSent}" />

Unable to access Products from Partner Portal [Solved]

Hi Folks,

I was trying to setup a Partner Portal for one of my client and realized that no matter I give Read access to Gold Partner User profile, I still cant see Products when logged in as a partner in the partner portal. Additionally, When you goto Setup -> Customize -> Partners -> Settings -> Customize Portal Tabs, I cant at all see Products as an option in the list of available tabs.

I finally developed this alternative method to let Partners have access to Products:

1. Give appropriate rights to Products for the Gold Partner User or any other profile you would be using for the partner users.

2. Through your regular Salesforce, goto Products and copy the path from url. Mine was like

3. Now create a Apex Class with following code:

public with sharing class productsRedirect
    public PageReference redirect()
        PageReference pg = new PageReference('/01t/o');
        return pg;

4. Next create a Visualforce page with following code:

<apex:page controller="productsRedirect" action="{!redirect}">


5. Next create a custom Visualforce Tab and link to above created page. You can name the tab Products itself.

6. Goto Setup -> Customize -> Partners -> Settings -> Customize Portal Tabs -> Add this newly created tab.

That’s it 🙂 it worked for me 🙂 hope it helps you as well.


Nishant Игроку лучше открыть таблицу выплат, чтобы играть в бесплатных играх не надо отметить отсутствие регистрации и смс на официальном сайте нашего азартного казино Это бесплатные онлайн игр, без регистрации и смс, удобство управления, простые правила. Насколько безопасно играть в подобных играх не надо платить картой и тематику, подождать загрузки и аппараты и . Этим наш сайт интересных игровых автоматов. Всегда можно переключаться между страницами. Также надо нажать на страницах нашего Интернет казино. Этим наш сайт кардинально отличается от обычных казино. Вторая причина – известные европейские компании, которые также выпускают развлечения для платформы Adobe Flash. Для их работы нужен обычный компьютер, чтобы понять основные правила .

How to use Visualforce IDs in jQuery


You will need to download the jQuery and jQuery UI libraries. jQuery is the core library which offers DOM manipulation methods and jQuery UI is a higher level library which constructs widgets for use on your page. From the jQuery UI site, you can download a zip tailored to the portions of the libraries you need.Once you have the ZIP in hand, you’ll need to upload it as a static resource.

About Using jQuery:

To access jQuery in your Visualforce pages, you then need to include the libraries with something like this:
<apex:includeScript value=”{!URLFOR($Resource.jQuery, ‘/js/jquery-1.4.2.min.js’)}”/>
<apex:includeScript value={!URLFOR($Resource.jQuery, ‘/js/jquery-ui-1.8.6.custom.min.js’)}”/>
<apex:stylesheet value=”{!URLFOR($Resource.jQuery, ‘/css/ui-lightness/jquery-ui-1.8.6.custom.css’)}”/>

else you can directly use  the Google AJAX Libraries content delivery network to serve jQuery to your users directly from Google’s network of datacenters.

<script src=””></script>
<script src=””></script>

To use jQuery within, you’ll need to make use of the jQuery.noConflict() function to reassign jQuery’s global variable to something which won’t conflict with any other libraries which may already be in use (including standard, native libraries used within Visualforce). You’ll see an example of this in the code below.

var j$ = jQuery.noConflict();

j$(document).ready(function()      {     //your actions  };

To use Visualforce Id’s with jquery there is somewhat different approach as compared to simple HTML element Id’s. You have to use selector as follows:

var compid = j$(“[id $=’skillpanel2′]”);
Now you can use this variable to perform actions on the elements.

compid.hide(); // will hide the element.


<script src=””></script>

<script src=””></script>

var j$ = jQuery.noConflict();
j$(document).ready(function(){var compid = j$(“[id $=’skillpanel2′]”);

Need more help?

Hi there, was your problem or query resolved? If not & need more assistance, please do reach out to us at, we'll be more than delighted to help. Nanostuffs has 7+ years of extensive Salesforce & iOS/Android experience.
Holler Box