In this article i am going to explain some of the programming solutions
1. Capture device screenshot programmatically
CGContextRef context = UIGraphicsGetCurrentContext();
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
Here, in above code we first pass the rect which we want to capture as image.Then we pass this rect
to beginContext method which take three parameters
rect of which we need screenshot
Captured image to be opaque or not
Image to be scaled
Then we started our CGContext and then we capture from current context.
2. Insert background image to toolBar
[toolBar insertSubview:[[[UIImageView alloc]
initWithImage:[UIImage imageNamed:@”BottomBar_iPad.png”]] autorelease] atIndex:1];
Here in above code we use insertSubview method of toolbar.
3. Show splash screen for certain interval of time
Here in above line we set main thread to sleep for 3 seconds. You can set value as per your need.
4. Send object with a selector
We can pass objects while calling our selector in objective C by wrapping object in withObject parameter. If you want to pass multiple objects then we can add our objects in an array and then pass that array to withObject parameter.
NSMutableArray *array = [[NSMutableArray alloc]initWithCapacity:0];
[NSThread detachNewThreadSelector:@selector(loadImage:) toTarget:self withObject:array];
#pragma mark Load image
NSMutableArray *array =(NSMutableArray *)sender;
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[array objectAtIndex:0]]];
UIImageView *img = [array objectAtIndex:1];
data = nil;
5. Compare two images
You can compare two images using below code
6. Get image name from UIImageView
To get image name from UIImageView, first you have to set image name to setAccessibilityIdentifier property of UIImage.
To get name of image from myImageview use the below code
NSLog(@”Image name of image assigned to myImageview is %@”,[myImageview.image accessibilityIdentifier]);
7. Allow your app awake until user press home button or close app
You can use below line of code to let your app awake until user press home button or close your app
8. Restrict device to receive touch interaction
In some cases, we need our app to ignore user touch events until a particular operation going on gets finished. You can do this by using below code
And to resume receiving user interaction events
9. Load view from an xib
To load a view from an xib, you can use below code
UIView *notificationView = [[[NSBundle mainBundle] loadNibNamed:@”NotificationManager” owner:self options:nil] objectAtIndex:0];
Above code will assign .xib file as view. So no need to create a view programmatically.Simply create an xib file and assign it to view.