How to convert string uppercase in iPhone?


Step 1: Open the Xcode, Create a new project using Single View Application. Give the application
“StringConvert”.
Step 2: Need to add new viewController class in the project. Select project -> New file ->
UIViewController subclass -> next -> Give the application name “StringConvertView”.
Step 3: Now open the AppDelegate.h file and make the following changes:
#import <UIKit/UIKit.h>
@class StringConvertView;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
StringConvertView
 *stringConvertView;
}
@property (nonatomic, retain)IBOutlet StringConvertView *stringConvertView;
Step 4: In the AppDelegate.m file make the following changes:
#import "AppDelegate.h"
#import "StringConvertView.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize stringConvertView;
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
self.window
 = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor
 = [UIColor whiteColor];
stringConvertView
 = [[StringConvertView alloc]
initWithNibName
:@"StringConvertView"
bundle
:nil];
[_window addSubview:stringConvertView.view];
[self.window makeKeyAndVisible];
return YES;
}
@end
Step 4: Now open the “StringConvertView.h” file and make the following changes:
#import <UIKit/UIKit.h>
@interface StringConvertView : UIViewController
{
IBOutlet UIButton
 *button;
IBOutlet UILabel
*resultText;
}
@property (nonatomic, retain) IBOutlet UIButton *button;
@property (nonatomic, retain) IBOutlet UILabel*resultText;
-(IBAction) uppercaseString:(id)sender;
@end
Step 5: Double click the StringConvertView.xib file and open it to the Interface Builder. First drag
the UIButton and UILabel from the library and place it to the view window. Select the button from
the view window and bring up connection inspector and connect touch up inside to the File’s Owner
icon and select “uppercaseString:” method and connect the File’s owner icon to the label and select
“resultText”. Now save the .xib file, close it and go back to the Xcode.
Step 6: In the StringConvertView.m file make the following changes:
#import "StringConvertView.h"
@implementation StringConvertView
@synthesize button,resultText;
-(IBAction) uppercaseString:(id)sender
{
NSString *string1 = @"welcome to iPhone";
NSString *upperString = [[NSString alloc] initWithFormat:string1];
NSStringchangeString = [upperString uppercaseString];
resultText.text
 = changeString ;
NSLog
(changeString);
}
(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self
 = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
(void)didReceiveMemoryWarning
{
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren’t in use.
}
#pragma mark – View lifecycle
(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
(void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
Step 7: Now compile and run the application on the Simulator.


Reactions: