Sunday, 22 July 2012 21:22 |
Here's one way of displaying only part of your UIImage in UIImageView. Yup. There could be many other ways to give you the same result. My example here is Mickey Mouse with full body and half-body displayed.
 
Insert this code in your loadView or viewDidLoad. Make sure your image file is imported in your project.
UIImage *image = [UIImage imageNamed:@"mickeymouse.png"];
CGImageRef imageToSplit = image.CGImage;
CGImageRef partOfImageAsCG = CGImageCreateWithImageInRect(imageToSplit, CGRectMake(0, 0, image.size.width, image.size.height/2));
UIImage *partOfImage = [UIImage imageWithCGImage:partOfImageAsCG];
UIImageView *imageView = [[UIImageView alloc]initWithImage:partOfImage];
[self.view addSubview:imageView];
Hope this helps!
|
|
Sunday, 15 July 2012 05:50 |
GuessTheShape is a simple iOS project that generates random shapes and the user will identify the name of the shape. When the user got it wrong, a label will show "Wrong!". The user has the option to click next to guess the next shape or try to solve it again. If the user got the shape name right, the label will display "Correct!" and displays the next shape.
The goal of this project really is to show how I would implement a question-and-answer kind of application. Thus, no fancy graphics and there are only 5 images that changes. Note that this project ONLY implements the following:
1. Generate random shape/image. Must not repeat consecutively.
2. UITextField hides when done button is tapped
3. Get value from UITextField and check if the user input (shape name) and the actual shape name. If correct, display "Correct". If wrong, display "Wrong".
That would be all! Hope you'll find this project helpful. You can find the source code here: https://github.com/HaifaCarina/GuessTheShape. And below are the screenshots.
 
 
|
Sunday, 15 July 2012 04:50 |
UITextField is very simple to create programmatically. As beginners, we expect that when we hit the return/done button the keyboard hides on its own. Unfortunately, it doesn't work that way. We had to do that on our own.
So in this post, I'll show you how to do that i 5 simple steps. I assume you already have a UIViewController to implement our UITextField.
1. Create simple UITextField instance
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 200, 180, 30)];
textField.borderStyle = UITextBorderStyleRoundedRect; // required. textfield will not display without this
[self.view addSubview: textField];
2. Implement the UITextFieldDelegate. That is, in our UIViewController's header file, we must insert <UITextFieldDelegate> beside our class declaration. Similar to this:
@interface RootViewController : UIViewController <UITextFieldDelegate> {
}
3. Set delegate to our object. In our case, we set it to itself. So our textField will now look like this.
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 200, 180, 30)];
textField.borderStyle = UITextBorderStyleRoundedRect; // required. textfield will not display without this
textField.delegate = self;
[self.view addSubview: textField];
4. Insert this somewhere in our implementation file.
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
5. Run and test.
That's it! In just 5 steps, we were able to implement a very useful feature of UITextField. :D
|
Sunday, 15 July 2012 02:34 |
If you're looking for a way of traversing items in an NSArray similar to foreach loop in PHP. Here's a simple example of its implementation where we log to console the values of the NSArray animals.
Our NSArray animals:
NSArray *animals = [[NSArray alloc]initWithObjects:
[NSString stringWithFormat:@"dog"],
[NSString stringWithFormat:@"cat"],
[NSString stringWithFormat:@"sheep"],
[NSString stringWithFormat:@"horse"],
[NSString stringWithFormat:@"lion"],
nil];
Our for loop implementation:
for (NSString *kind in shapes) {
NSLog(@"%@", kind);
}
Hope this helps!
|
Tuesday, 24 January 2012 18:07 |
 
SimpleActionSheet is an Objective-C project that programmatically implements UIActionSheet and UIBarButtonItem. It displays a button in the navigationbar and when clicked, displays the actionsheet.
Download project here.
|
Monday, 22 August 2011 14:41 |

Preloader is a simple Objective-C project that displays a preloader using UIProgressView while the data is being loaded and displays the PDF file after data loading is complete.
You can download the project here.
The project only contains one UIViewController. I've written comments in the code too.
But I still would like to share a quick overview:
Quick Flow of PreloaderViewController.m (i recommend looking at the code while reading this so you can get the grasp ):
1. loadView method
a. sets PDF url string
b. initialize UIWebView. The PDF file gets displayed using the UIWebView
c. initialize the UIProgressView and UILabel (which is 0%)
d. start NSURLConnection which loads the file
2. didReceiveResponse method
a. When the NSURLConnection gets response, it will display the UIProgressView and UILabel.
b. initialize the totalfilesize variable
c. initialize the receivedData variable to 0
3. didReceiveData method
a. does the calculation everytime a data is received and increments the progress values
4. connectionDidFinishLoading method
a. displays the PDF file
Drop a comment if you find this post helpful. Cheers! :D
|
Friday, 19 August 2011 17:20 |

SimpleTable is a Objective-C project that implements the basic use of UITableView.
Download project here.
Drop a comment if you find this post helpful. Cheers! :D
|
Friday, 19 August 2011 15:40 |
JSONPDFTutorial is a simple Objective C project that reads a JSON file and displays the values in a TableView.
You'll see the content of the JSON file here.
Download project here.
Drop a comment if you find this post helpful. Cheers! :D
|
Thursday, 18 August 2011 20:59 |

WebBrowserTutorial is a simple Objective-C project that shows the content of a URL.
Download project here.
Drop a comment if you find this post helpful. Cheers! :D
|
Thursday, 18 August 2011 20:49 |

TabExample is an Objective-C project that shows the implementation of UITabBarController.
Download project here.
Drop a comment if you find this post helpful. Cheers! :D
|
Thursday, 18 August 2011 20:43 |

NavigateImageTable is an Objective-C project that displays a list of countries and when selected, opens a new view which displays the flag image of the country.
Download project here.
Drop a comment if you find this post helpful. Cheers! :D
|
|
|
|
<< Start < Prev 1 2 Next > End >>
|
Page 1 of 2 |