Thursday, 28 April 2011

Change UISlider Image in Iphone


There are three images in UISlider you can change

1) left (default blue)
2) right (default white)
3) thumb (default white circle)


UIImage *sliderLeftTrackImage = [[UIImage imageNamed: @"SliderMin.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0];

UIImage *sliderRightTrackImage = [[UIImage imageNamed: @"SliderMax.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0];

1)
[mySlider setMinimumTrackImage: sliderLeftTrackImage forState: UIControlStateNormal];

2)
[mySlider setMaximumTrackImage: sliderRightTrackImage forState: UIControlStateNormal];

3)
[mySlider setThumbImage:[UIImage imageNamed:@"thumb_image.png"] forState:UIControlStateNormal];

Wednesday, 27 April 2011

Use Google Analytics in iphone

Please see these links

1) http://code.google.com/mobile/analytics/docs/iphone/

2) http://www.icodeblog.com/2010/04/22/how-to-integrate-google-analytics-tracking-into-your-apps-in-7-minutes/

3) Sample code also available in this link
http://code.google.com/intl/fr/mobile/analytics/download.html#Google_Analytics_SDK_for_iOS

Sunday, 24 April 2011

How to convert Seconds into minutes

for example

70 second = 1 minute and 10 second


double progress = ...... ;
int minutes = floor(progress/60);
int seconds = trunc(progress - minutes * 60);

Load Local html file using UIWebView

Ok here is the single line you need to load local html files :

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"01" ofType:@"html"]isDirectory:NO]]];


This line loads a html-file named '01.html' which has to be located in your project resources.

Saturday, 23 April 2011

Reserved characters after percent-encoding

! %21
* %2A
' %27
( %28
) %29
; %3B
: %3A
@ %40
& %26
= %3D
+ %2B
$ %24
, %2C
/ %2F
? %3F
# %23
[ %5B
] %5D

Friday, 22 April 2011

Split one string into different strings

NSString *str = @"011597464952,01521545545,454545474,454545444|Hello this is were the message is.";

NSArray *firstSplit = [str componentsSeparatedByString:@"|"];
NSAssert(firstSplit.count == 2, @"Oops! Parsed string had more than one |, no message or no numbers.");
NSString *msg = [firstSplit lastObject];
NSArray *numbers = [[firstSplit objectAtIndex:0] componentsSepratedByString:@","];

// print out the numbers (as strings)
for(NSString *currentNumberString in number) {
NSLog(@"Number: %@", currentNumberString);
}

Friday, 15 April 2011

get Time from NSDate


NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterNoStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString* currentTime = [dateFormatter stringFromDate:[NSDate date]];
[dateFormatter release];


UITextField: how to dismiss the Keyboard and Number Pad Keyboard

There are two ways, second is the easy way.


1) define delegate and

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}



2)


-(void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event
{
// do the following for all textfields in your current view
[self.txtfieldname resignFirstResponder];
// save the value of the textfield, ...
}

3) Dismiss textview    

Define Delegate

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
   
    if([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
   
    return YES;
}