Monday 24 December 2012

How to remove the null or space from string? , use these two methods..




-(NSString*) trimString:(NSString *)theString {
NSString *theStringTrimmed = [theString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
return theStringTrimmed;
}

-(NSString *) removeNull:(NSString *) string {    
    
NSRange range = [string rangeOfString:@"null"];
    //NSLog(@"in removeNull : %d  >>>> %@",range.length, string);
if (range.length > 0 || string == nil) {
string = @"";
}
string = [self trimString:string];
return string;
}

And call it like bellow...

        NSString *str = yourStringValue;
        str = [self removeNull:str];

Change the Appearance and BackGroundImage of cancel button of UISearchBar


  This bellow code for change the cancel button of UISearchBar
    
    for (UIView *possibleButton in searchBar.subviews)
    {
        if ([possibleButton isKindOfClass:[UIButton class]])
        {
            UIButton *cancelButton = (UIButton*)possibleButton;
            cancelButton.enabled = YES;
            [cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];            
            [cancelButton setBackgroundImage:[UIImage imageNamed:@"mainbg1.png"] forState:UIControlStateNormal];
            [cancelButton setBackgroundImage:[UIImage imageNamed:@"mainbg.png"] forState:UIControlStateHighlighted];
            break;
        }
    }
     

Set Italic and Bold Font to UILable and anything else...



You have to actually ask for the bold, italic version of a font. For example:
UIFont *myFont = [UIFont fontWithName:@"Helvetica-BoldOblique" size:[UIFont systemFontSize]];
To get a list of everything available on the iPhone, put this little snippet in yourapplicationDidFinishLaunching: delegate method and look at the log output:
for (NSString *family in [UIFont familyNames]) {
    NSLog(@"%@", [UIFont fontNamesForFamilyName:family]);
}
Note: Some font names say "oblique" - this is the same as italic.
I can't see a built-in way of doing underlines - you may have to draw the line yourself.

Wednesday 19 December 2012

UserDefault with NSMutableArray ..


    In AppDelegate.h file just declare variable...
    
    NSUserDefaults  *userDefaults;
    NSMutableArray *yourArray;
    after...
    
    In AppDelegate.m Fille in applicationDidFinishLonching: Method
    
    userDefaults = [NSUserDefaults standardUserDefaults];
    NSData *dataRepresentingtblArrayForSearch = [userDefaults objectForKey:@"yourArray"];
    if (dataRepresentingtblArrayForSearch != nil) {
        NSArray *oldSavedArray = [NSKeyedUnarchiver unarchiveObjectWithData:dataRepresentingtblArrayForSearch];
        if (oldSavedArray != nil)
            yourArray = [[NSMutableArray alloc] initWithArray:oldSavedArray];
        else
            yourArray = [[NSMutableArray alloc] init];
    } else {
        yourArray = [[NSMutableArray alloc] init];
    }
    [yourArray retain];

    after that when you want to insert Data in this UserDefaults Use Bellow Code...
    
    [appDelegate.yourArray addObject:yourDataString];///set your value or anything which you want to store here...
    NSData *data=[NSKeyedArchiver archivedDataWithRootObject:appDelegate.yourArray];
    [appDelegate.userDefaults setObject:data forKey:@"yourArray"];
    [appDelegate.userDefaults synchronize];

And when you want to retrive data just retrive like bellow..

 i hope this help you...

Tuesday 11 December 2012

Append string with file extention


NSString *filename = @"DSC004.jpg";//suppose file name this or also file.some.jpg then it also work in the condition
NSString *ext = [filename pathExtension];
NSString *basename = [filename stringByDeletingPathExtension];
NSString *updated = [basename stringByAppendingString:@"-Add"];
NSString *finalName = [updated stringByAppendingPathExtension:ext];

Wednesday 5 December 2012

Custom Button



UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
playButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);
[playButton setTitle:@"Play" forState:UIControlStateNormal];
playButton.backgroundColor = [UIColor clearColor];
[playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];

UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"];
UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];

UIImage *buttonImagePressed = [UIImage imageNamed:@"whiteButton.png"];
UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[playButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];

[playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:playButton];