Browse Author: surjit.joshi

Get SIM card details of iPhone

Here is the code to get SIM card details of iPhone

1) Add CoreTelephony framework

2) Import following libraries

#import <CoreTelephony/CTCarrier.h>

#import <CoreTelephony/CTTelephonyNetworkInfo.h>

3) Use this code to get details

CTTelephonyNetworkInfo* info = [[CTTelephonyNetworkInfo alloc] init];

CTCarrier* carrier = info.subscriberCellularProvider;

NSString *carrierName = carrier.carrierName;

NSLog(@”carrier : %@”, carrier);

// Here are some parameters

//NSString *mobileCountryCode = carrier.mobileCountryCode;

//NSString *isoCountryCode = carrier.isoCountryCode;

//NSString *mobileNetworkCode = carrier.mobileNetworkCode;

 

 

 

Can we create flashing red/blue circle around user location in mapview in iPhone ?

Yes we can create with a simple UIView animation & few images.

1) Add the MapView

MKMapView *mapView = [[MKMapView alloc] initWithFrame:yourFrameFrame];

mapView.mapType = MKMapTypeStandard;

mapView.delegate = self;

[mapView setShowsUserLocation:YES];

[self.view addSubview:mapView];

 

2) In viewForAnnotation method
– (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation: (id <MKAnnotation>)annotation

{

UIImage *anImage = nil;

UIImageView *overlayImage;

if (annotation == mapview.userLocation)

{

MKPinAnnotationView *customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@”annotation”] autorelease];

customPinView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@”redLocation.png” ofType:nil]];

customPinView.animatesDrop = NO;

customPinView.canShowCallout = YES;

 

overlayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”OverlayImage.png”]];

overlayImage.frame = CGRectMake(0, 0, 15, 15);

overlayImage.center = CGPointMake(customPinView.center.x+7, customPinView.center.y+7);

[customPinView addSubview:overlayImage];

// timer for animation

NSTimer *mapTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(createOverlayAnimation) userInfo:nil repeats:YES];

 

 

return customPinView;

}

}

-(void)createOverlayAnimation

{

overlayImage.transform = CGAffineTransformMakeScale(1,1);

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:1.0];

overlayImage.transform = CGAffineTransformMakeScale(5,5);

overlayImage.alpha = 1.0;

[UIView commitAnimations];

}

Using FBGraph in iPhone

The FBGraph API is bit complex, but much useful than any other ways for accessing contents of Facebook.

INTRODUCTION

============

Object Output:

{

“name”: “Facebook Platform”,

“type”: “page”,

“website”: “http://developers.facebook.com”,

“username”: “platform”,

“founded”: “May 2007”,

“company_overview”: “Facebook Platform enables anyone to build…”,

“mission”: “To make the web more open and social.”,

“products”: “Facebook Application Programming Interface (API)…”,

“fan_count”: 449921,

“id”: 19292868552,

“category”: “Technology”

}

 

All objects in Facebook can be accessed in the same way:

https://graph.facebook.com/ID/CONNECTION_TYPE

 

* Users: https://graph.facebook.com/btaylor (Bret Taylor)

* Pages: https://graph.facebook.com/cocacola (Coca-Cola page)

* Events: https://graph.facebook.com/251906384206 (Facebook Developer Garage

Austin)

* Groups: https://graph.facebook.com/2204501798 (Emacs users group)

* Applications: https://graph.facebook.com/2439131959 (the Graffiti app)

* Status messages: https://graph.facebook.com/367501354973 (A status message

from Bret)

* Photos: https://graph.facebook.com/98423808305 (A photo from the Coca-Cola

page)

* Photo albums: https://graph.facebook.com/99394368305 (Coca-Cola’s wall

photos)

* Videos: https://graph.facebook.com/614004947048 (A Facebook tech talk on

Tornado)

* Notes: https://graph.facebook.com/122788341354 (Note announcing Facebook

for iPhone 3.0)

 

Logged-in User Objects

 

* Friends: https://graph.facebook.com/me/friends

* News feed: https://graph.facebook.com/me/home

* Profile feed (Wall): https://graph.facebook.com/me/feed

* Likes: https://graph.facebook.com/me/likes

* Movies: https://graph.facebook.com/me/movies

* Books: https://graph.facebook.com/me/books

* Notes: https://graph.facebook.com/me/notes

* Photos: https://graph.facebook.com/me/photos

* Videos: https://graph.facebook.com/me/videos

* Events: https://graph.facebook.com/me/events

* Groups: https://graph.facebook.com/me/groups

 

SELECTION

=========

fields => https://graph.facebook.com/bgolub?fields=id,name,picture

ids => https://graph.facebook.com?ids=arjun,vernal

current user => https://graph.facebook.com/me

 

INSTROSPECTION

==============

https://graph.facebook.com/331218348435?metadata=1

 

{

“name”: “Facebook Developer Garage Austin – SXSW Edition”,

“metadata”: {

“connections”: {

“feed”: “http://graph.facebook.com/331218348435/feed”,

“picture”: “https://graph.facebook.com/331218348435/picture”,

“invited”: “https://graph.facebook.com/331218348435/invited”,

“attending”: “https://graph.facebook.com/331218348435/attending”,

“maybe”: “https://graph.facebook.com/331218348435/maybe”,

“noreply”: “https://graph.facebook.com/331218348435/noreply”,

“declined”: “https://graph.facebook.com/331218348435/declined”

}

}

}

 

AUTHORIZATION

=============

https://graph.facebook.com/220439?access_token=…

 

The steps to obtain an access token are:

 

* Get App ID and secret.

 

* Redirect the user to https://graph.facebook.com/oauth/authorize with your

client_id and the callback URL:

 

https://graph.facebook.com/oauth/authorize?

client_id=…&

redirect_uri=http://www.example.com/oauth_callback

 

* Redirect the user back to the callback URL you specified with a verification

string in the argument code, which can be exchanged for an oauth access token.

 

https://graph.facebook.com/oauth/access_token?

client_id=…&

redirect_uri=http://www.example.com/oauth_callback&

client_secret=…&

code=…

 

* Use the access token returned by the request above to make requests on behalf

of the user:

 

https://graph.facebook.com/me?access_token=…

 

PUBLISH TO FACEBOOK

===================

curl -F ‘access_token=…’

-F ‘body=Hello, Arjun. I like this new API.’

https://graph.facebook.com/arjun/feed

 

curl -F ‘access_token=…’

https://graph.facebook.com/313449204401/likes

 

 

We support writing the following types of objects:

 

Method               Description                           Arguments

 

——————————————————————————-

/PROFILE_ID/feed     write to the given profile’s feed/wall message,

picture, link, name, description

/POST_ID/comments   comment on the given post             message

/POST_ID/likes       like the given post                   none

/PROFILE_ID/notes   write a note on the given profile     message, subject

/PROFILE_ID/links   write a link on the given profile     link, message

/EVENT_ID/attending attend the given event                 none

/EVENT_ID/maybe     maybe attend the given event           none

/EVENT_ID/declined   decline the given event               none

 

curl -F ‘access_token=…’

-F ‘message=I am posting to my own feed. I am awesome.’

https://graph.facebook.com/me/feed

 

DELETING OBJECT

===============

DELETE https://graph.facebook.com/ID?access_token=… HTTP/1.1

https://graph.facebook.com/COMMENT_ID?method=delete

 

PICTURES

========

<img src=”https://graph.facebook.com/herryanto/picture”/>

 

* People: http://graph.facebook.com/herryanto/picture

* Events: http://graph.facebook.com/331218348435/picture

* Groups: http://graph.facebook.com/335845912900/picture

* Pages: http://graph.facebook.com/DoloresPark/picture

* Applications: http://graph.facebook.com/2318966938/picture

* Photo Albums: http://graph.facebook.com/platform/picture

 

PICTURE SIZES:

– square (50×50)

– small  (50 pixels wide, variable height)

– large (about 200 pixels wide, variable height)

 

http://graph.facebook.com/herryanto/picture?type=large.

 

PAGING

======

 

* limit, offset: https://graph.facebook.com/me/likes?limit=3

* until, since (a unix timestamp or any date accepted by strtotime):

 

https://graph.facebook.com/search?until=yesterday&q=orange

 

SEARCH

======

https://graph.facebook.com/search?q=QUERY&type=OBJECT_TYPE

 

* All public posts: https://graph.facebook.com/search?q=watermelon&type=post

* People: https://graph.facebook.com/search?q=mark&type=user

* Pages: https://graph.facebook.com/search?q=platform&type=page

* Events: https://graph.facebook.com/search?q=conference&type=event

* Groups: https://graph.facebook.com/search?q=programming&type=group

 

News Feed: https://graph.facebook.com/me/home?q=facebook

 

ANALYTICS

=========

 

Obtain Access Token:

 

curl -F type=client_cred

-F client_id=your_app_id

-F client_secret=your_app_secret

https://graph.facebook.com/oauth/access_token

 

https://graph.facebook.com/app_id/insights?access_token=…

 

https://graph.facebook.com/app_id/insights/share_views/day?access_token=…

 

Params:

* since

* until

 

https://graph.facebook.com/app_id/insights?access_token=…&since=yesterday

 

Now, Passing these parameters to FBGraph in iPhone way.

1) Get Authentication (get access_token) :

/*Facebook Application ID*/

NSString *client_id = @“your app id”;

//alloc and initalize our FbGraph instance

self.fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];

// //begin the authentication process…..

[fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallbackForRegister:)
andExtendedPermissions:@”user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins,email,user_birthday,user_online_presence” andSuperView:self.view] ;

**Note : fbGraphCallbackForRegister method returns access_token.

 

2) Logged-In UserInfo :

FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@”me” withGetVars:nil];

NSLog(@”getMeButtonPressed:  %@”, fb_graph_response.htmlResponse);

3) Get Logged-In user profile picture :
There are few sizes of profile picture.

http://graph.facebook.com/herryanto/picture?type=large

http://graph.facebook.com/herryanto/picture

 

4) Get User Friends (Needs authentication)

FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:@”me/friends” withGetVars:nil];

NSLog(@”getFriendsButtonPressed:  %@”, fb_graph_response.htmlResponse);

 


 

 

Draw a line by touch On UIImageView in iPhone

Its much useful for drawing something on screen by touch.

1) Declare 4 objects in .h file

CGPoint lastPoint;

BOOL mouseSwiped;

int mouseMoved;

UIImageView *signImage;
2) First create a UIImageView object ie. a blank image in viewDidLoad

signImage = [[UIImageView alloc ] initWithFrame:CGRectMake(15, 60, 290, 320)];

signImage.image = nil;

signImage.tag = 1000;

signImage.layer.borderWidth = 3.0;

signImage.layer.borderColor = [[UIColor lightGrayColor] CGColor];

[self.view addSubview:signImage];

 

2) Then add 3 methods TouchesBegin, TouchesMoved & TouchesEnd

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

mouseSwiped = NO;

UITouch *touch = [touches anyObject];

CGPoint touchLocation = [touch locationInView:self.view];

 

if (CGRectContainsPoint(signImage.frame, touchLocation))

{

lastPoint = [touch locationInView:signImage];

}

 

NSLog(@”Last :%.2f – %.2f”,lastPoint.x, lastPoint.y);

}

 

– (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

mouseSwiped = YES;

CGPoint currentPoint;

UITouch *touch = [touches anyObject];

CGPoint touchLocation = [touch locationInView:self.view];

 

if (CGRectContainsPoint(signImage.frame, touchLocation))

{

currentPoint = [touch locationInView:signImage];

UIGraphicsBeginImageContext(signImage.frame.size);

[first_signImage.image drawInRect:CGRectMake(0, 0, signImage.frame.size.width, signImage.frame.size.height)];

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);

CGContextBeginPath(UIGraphicsGetCurrentContext());

CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);

CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);

CGContextStrokePath(UIGraphicsGetCurrentContext());

signImage.image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

}

 

//currentPoint.y -= 150;

 

lastPoint = currentPoint;

 

mouseMoved++;

 

if (mouseMoved == 10) {

mouseMoved = 0;

}

 

}

 

– (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

if(!mouseSwiped) {

 

CGPoint currentPoint;

UITouch *touch = [touches anyObject];

CGPoint touchLocation = [touch locationInView:self.view];

 

if (CGRectContainsPoint(signImage.frame, touchLocation))

{

currentPoint = [touch locationInView:signImage];

 

UIGraphicsBeginImageContext(signImage.frame.size);

[signImage.image drawInRect:CGRectMake(0, 0, signImage.frame.size.width, signImage.frame.size.height)];

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);

CGContextBeginPath(UIGraphicsGetCurrentContext());

CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);

CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);

CGContextStrokePath(UIGraphicsGetCurrentContext());

signImage.image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

}

}

}

 

 

Simple Custom UITabBarController with UINavigationController in iPhone/iPad programatically

//In AppDelegate.h file

UITabBarController *tabBarController;

@property (strong, nonatomic) UITabBarController *tabBarController;

 

//In AppDelegate.h.m file

@synthesize tabBarController = _tabBarController;

 

 

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

 

NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] init];

 

self.tabBarController = [[[UITabBarController alloc] init] autorelease];

 

UIViewController *viewController1 = [[[ViewController1 alloc] initWithNibName:@“ViewController1″ bundle:nil] autorelease];

UIViewController *viewController2 = [[[ViewController2 alloc] initWithNibName:@”ViewController2″ bundle:nil] autorelease];

UIViewController *viewController3 = [[[ViewController3 alloc] initWithNibName:@”ViewController3″ bundle:nil] autorelease];

UIViewController *viewController4 = [[[ViewController4 alloc] initWithNibName:@”ViewController4″ bundle:nil] autorelease];

UIViewController *viewController5 = [[[ViewController5 alloc] initWithNibName:@”ViewController5″ bundle:nil] autorelease];

 

UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];

UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];

UINavigationController *navigationController3 = [[UINavigationController alloc] initWithRootViewController:viewController3];

UINavigationController *navigationController4 = [[UINavigationController alloc] initWithRootViewController:viewController4];

UINavigationController *navigationController5 = [[UINavigationController alloc] initWithRootViewController:viewController5];

 

navigationController1.navigationBar.barStyle = UIBarStyleDefault;

navigationController2.navigationBar.barStyle = UIBarStyleDefault;

navigationController3.navigationBar.barStyle = UIBarStyleDefault;

navigationController4.navigationBar.barStyle = UIBarStyleDefault;

navigationController5.navigationBar.barStyle = UIBarStyleDefault;

 

navigationController1.navigationBar.tintColor = [UIColor whiteColor];

navigationController2.navigationBar.tintColor = [UIColor blackColor];

navigationController3.navigationBar.tintColor = [UIColor blackColor];

navigationController4.navigationBar.tintColor = [UIColor blackColor];

navigationController5.navigationBar.tintColor = [UIColor blackColor];

 

navigationController4.navigationItem.hidesBackButton = YES;

 

//viewController1.title = @”ViewController1″;

viewController2.title = @”ViewController2″;

viewController3.title = @”ViewController3″;

viewController4.title = @”ViewController4″;

viewController5.title = @”ViewController5″;

 

[tabBarViewControllers addObject:navigationController1];

[tabBarViewControllers addObject:navigationController2];

[tabBarViewControllers addObject:navigationController3];

[tabBarViewControllers addObject:navigationController4];

[tabBarViewControllers addObject:navigationController5];

 

self.tabBarController.viewControllers = tabBarViewControllers;

 

self.window.rootViewController = self.tabBarController;

 

[self.window makeKeyAndVisible];

 

Play YouTube video using UIWebView on iPhone

Hi,

Sometimes it gets very difficult to find a way to do simple things. Playing videos on iPhone is a simple thing, using UIWebView. Just need to embed the URL to HTML tags, and then load the HTML in UIWebView.

Here is the code to do so.

Pass you URL of YouTube Video in “urlStr”.

//In .h file
UIWebView *videoView;
// In .m file

videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 385)];

[self embedYouTube :urlStr  frame:CGRectMake(0, 0, 320, 385)];

[self.view addSubview:videoView];

// methos to embed URL in HTML & load it to UIWebView

– (void)embedYouTube:(NSString*)url frame:(CGRect)frame

{

NSString* embedHTML = @”

<html><head>

<style type=”text/css”>

body {

background-color: transparent;

color: white;

}

</style>

</head><body style=”margin:0″>

<embed id=”yt” src=”%@” type=”application/x-shockwave-flash”

width=”%0.0f” height=”%0.0f”></embed>

</body></html>”;

 

NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];

if(videoView == nil) {

videoView = [[UIWebView alloc] initWithFrame:frame];

[self.view addSubview:videoView];

}

[videoView loadHTMLString:html baseURL:nil];

}

**Note : The UIWebView for YouTube video doesn’t load when you run it on Simulator, work on device perfectly.

 

Five ways to pull yourself out of workaholism

‘In sickness and in health and till death do us part’ – if these are the vows your family and friends think you have exchanged with your Blackberry/keyboard/iPad, then you are a certified workaholic.

The symptoms are many, but some of the significant ones are that you punch away nonstop, receive every call from office and take your meals at odd hours to finish that extra bit at work.

All this leads to anxiety disorders, repetitive stress injury, mental and physical fatigue, and this strong alliance with work is best severed at the start. ET suggests how you can do that.

 

Draw Clear Boundaries

Clocking out of work is just as important as clocking in. Working post-office hours is acceptable if there is an urgent assignment but if it becomes a habit, alarm bells should start ringing. It helps to unplug phones and computers during vacations and non-working hours.

Check on Employees

Employers need to look into the employees’ attendance sheets and office hours. Sabre, for instance, found that despite giving employees access to wellness centres, counselling sessions and discount coupons at gyms, they were still packing in extra hours at work. The firm, therefore, does not offer the option of carrying forward holidays .

Say a Firm ‘No’

‘Workaholics anonymous’ groups don’t exist, but instead, a simple ‘no’ can go a long way. Complete your tasks first, and only if there is time to spare, offer another a helping hand. Once the tasks are done, wait for the next day to start on the new list of chores.

Extra isn’t Always Healthy

The boss often thinks that those who work round the clock are the productive ones. But a smart worker can be someone who punches in the required hours, completes his work and leaves office on time too.

In a recent Randstad survey of state-owned companies, 80% of employees said they received work-related calls and emails beyond office hours. Nearly 69% said they volunteered to work post-office hours while 79% received work-related calls and emails on holidays. Long hours lead to a dip in productivity and creativity.

Watch your Schedule

Often, the employee in the cubicle next to you could be a night owl at the office, but that need not be your style. Excessive breaks, long water-cooler conversations will ultimately lead to more time in the office, and not a very fruitful schedule.

So what’s the moral of the story??
* Very clear, LEAVE ON TIME!!!
* Never put in extra time ‘ unless really needed ‘
* Don’t stay back unnecessarily and spoil your company work culture which will in turn cause inconvenience to you and your colleagues.

How to create iPhone/iPad’s “Slide to Unlock” animation ?

This is how Apple implemented “Slider to Unlock” or “Slide to Power off” animation.

In .h file

UISlider *slider;

BOOL touchIsDown;

CALayer *textLayer;

 

 

– (void)viewDidLoad

{

self.view.layer.backgroundColor = [[UIColor grayColor] CGColor];

UIImageView *sliderBackView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”SliderBack1.png”]];

sliderBackView.frame = CGRectMake(20, 20, 260, 50);

sliderBackView.userInteractionEnabled = YES;

[self.view addSubview:sliderBackView];

 

slider = [[UISlider alloc] initWithFrame:CGRectMake(5, 12, 250, 27)];

[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];

[slider addTarget:self action:@selector(sliderUp:) forControlEvents:UIControlEventTouchUpInside];

[slider addTarget:self action:@selector(sliderDown:) forControlEvents:UIControlEventTouchDown];

slider.minimumValue = 0;

slider.maximumValue = 100;

slider.value = 0;

slider.continuous = YES;

slider.backgroundColor = [UIColor clearColor];

[slider setMinimumTrackImage:[UIImage imageNamed: @”transSlider.png”] forState:UIControlStateNormal];

[slider setMaximumTrackImage:[UIImage imageNamed: @”transSlider.png”] forState:UIControlStateNormal];

[slider setThumbImage:[UIImage imageNamed:@”SliderThumb.png”] forState:UIControlStateNormal];

[sliderBackView addSubview:slider];

 

NSString *labelText = @”Slide to Unlock”;

UIFont *labelFont = [UIFont systemFontOfSize:18];

CGSize labelSize = [labelText sizeWithFont:labelFont];

 

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 0.0, labelSize.width, labelSize.height)];

label.textColor = [UIColor whiteColor];

label.textAlignment = UITextAlignmentCenter;

label.backgroundColor = [UIColor clearColor];

label.font = labelFont;

label.text = labelText;

 

UIGraphicsBeginImageContext(label.bounds.size);

[label.layer renderInContext:UIGraphicsGetCurrentContext()];

CGImageRef viewImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage];

UIGraphicsEndImageContext();

 

UIImage *textImage = [UIImage imageWithCGImage:viewImage];

 

CGFloat textWidth = textImage.size.width;

CGFloat textHeight = textImage.size.height;

 

textLayer = [CALayer layer];

textLayer.contents = (id)[textImage CGImage];

textLayer.frame = CGRectMake(78.0f, 15.0f, textWidth, textHeight);  //set frame here

 

CALayer *maskLayer = [CALayer layer];

 

// Mask image ends with 0.15 opacity on both sides. Set the background color of the layer

// to the same value so the layer can extend the mask image.

maskLayer.backgroundColor = [[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.15f] CGColor];

maskLayer.contents = (id)[[UIImage imageNamed:@”Mask.png”] CGImage];

 

// Center the mask image on twice the width of the text layer, so it starts to the left

// of the text layer and moves to its right when we translate it by width.

maskLayer.contentsGravity = kCAGravityCenter;

maskLayer.frame = CGRectMake(-textWidth, 0.0f, textWidth * 2, textHeight);

 

// Animate the mask layer’s horizontal position

CABasicAnimation *maskAnim = [CABasicAnimation animationWithKeyPath:@”position.x”];

maskAnim.byValue = [NSNumber numberWithFloat:textWidth];

maskAnim.repeatCount = 1e100f;

maskAnim.duration = 1.5f;

[maskLayer addAnimation:maskAnim forKey:@”slideAnim”];

 

textLayer.mask = maskLayer;

[sliderBackView.layer addSublayer:textLayer];

 

 

[super viewDidLoad];

}

 

– (IBAction) sliderAction : (id) sender

{

NSLog(@”%f”, slider.value);

textLayer.opacity = MAX(0.0, 1.0 – (slider.value * 3.5));

 

if(slider.value >= 45)

{

//slider.value = slider.maximumValue;

 

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:0.3];

slider.value = slider.maximumValue;

[UIView commitAnimations];

 

textLayer.opacity = MAX(0.0, 1.0 – (slider.value * 3.5));

 

}

else

{

if(slider.value >= 5)

{

textLayer.opacity = textLayer.opacity-0.05;

}

}

 

}

 

– (void) sliderUp: (UISlider *) sender

{

if (touchIsDown)

{

touchIsDown = NO;

 

if(slider.value < 45)

{

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:0.3];

slider.value = slider.minimumValue;

[UIView commitAnimations];

 

textLayer.opacity = 1.0;

}

}

}

 

– (void) sliderDown: (UISlider *) sender

{

touchIsDown = YES;

 

}

This is complete code for Lazy People..

How to Create UILocalNotification, repeating every minute ?

There are two types of notifications in iOS, One is Local notification & other is PUsh notification. Added code to create Local notification.

// creating notification
NSDate *newDate = [NSDate dateWithTimeIntervalSinceNow:60];

// where 60 = seconds, so add your seconds here
Class cls = NSClassFromString(@”UILocalNotification”);
if (cls != nil) {
UILocalNotification *notification = [[cls alloc] init];
notification.fireDate = newDate;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = @“My Notification”;
notification.alertAction = @”Show me”;
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;
notification.repeatInterval = NSMinuteCalendarUnit;
NSString *str = @“String to pass”;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:str forKey:@“myNotification”];
notification.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];
}

// receiving notification
– (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@”Notification: %@”, [notification.userInfo objectForKey:@“myNotification”]);
}


Need more help?

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