Tuesday, 24 December 2013

How to sort an array with respect to another

You can sort an array with respect to another easily by adding them to an NSDictionary and do as follows:
            
    // Put the two arrays into a dictionary as keys and values
    NSDictionary *dictionary = [NSDictionary 
                               dictionaryWithObjects:secondArray forKeys:firstArray];
    // Sort the first array
    NSArray *sortedFirstArray = [[dictionary allKeys]  
                               sortedArrayUsingSelector:@selector(compare:)];
    // Sort the second array based on the sorted first array

    NSArray *sortedSecondArray = [dictionary objectsForKeys:sortedFirstArray 
                                             notFoundMarker:[NSNull null]];

How to set an image at the left corner of an UIButton

Let button Frame is:

  myButton.frame = CGRectMake(008030);

            
To set an image at the left corner of an UIButton, do as follows:

  [myButton setImageEdgeInsets:UIEdgeInsetsMake(030080)];