Skip to main content

Draw shapes in iPhone.

Hi Folks,
              You would have seen shapes, graphs in iPod, iPhone and iPad. Have you ever thought about the code behind it. Here it is. I am going to show simple code to draw shapes. In iPhone, its just like joining the co-ordinates. Here it goes.
Step 1: Create a ViewController in my case, its SampleViewController. And create a UIView in my case its just SampleView.
Step 2: In your AppDelegate implementation file create an instance for ViewController like this. Create the instance in didFinishLaunchingWithOptions delegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{      
  
// Override point for customization after application launch.

// Add the view controller’s view to the window and display.

SampleViewController *ControllerInstance = [[SampleViewController alloc]                                         initWithNibName:@”SampleGraphViewController” bundle:nil];

[window addSubview:ControllerInstance.view];
  
[window makeKeyAndVisible];

return YES;
}
Step 3: Create instance of UIView in your ViewController implementation file.
- (void)viewDidLoad {
    [super viewDidLoad];
SampleGraph *ViewInstance = [[SampleGraph alloc]initWithFrame:self.view.frame];
[self.view addSubview:ViewInstance];
[ViewInstance release];
}
Don’t forget to import the files. SampleView.h in SampleViewController.m and SampleViewController.h in AppDelegate.m
Step 4: Add the following code in SampleView.m in the delegate - (void)drawRect:(CGRect)rect as follows.
- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Initialization code
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
//Draw a Vertical Line.
 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextSetStrokeColorWithColor(context,[UIColor grayColor].CGColor);
 CGContextSetLineWidth(context,10.0);
 CGContextMoveToPoint(context, 100.0,100.0);
 CGContextAddLineToPoint(context, 100.0,500.0);
 CGContextStrokePath(context);

//Draw a rectangle.
 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextSetStrokeColorWithColor(context,[UIColor grayColor].CGColor);
 CGContextSetLineWidth(context,10.0);

 CGRect rectangle = CGRectMake(60,170,200,80);
 CGContextAddRect(context, rectangle);
 CGContextStrokePath(context);

//Filling color inside the rectangle.
 CGContextRef context = UIGraphicsGetCurrentContext();
 CGContextSetStrokeColorWithColor(context,[UIColor grayColor].CGColor);
 CGContextSetLineWidth(context,10.0);

 CGRect rectangle = CGRectMake(60,170,200,80);
 CGContextAddRect(context, rectangle);
 CGContextStrokePath(context); 

CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextFillRect(context, rectangle);

}
P.S : You can try this only if you have a Mac OS ie. Apple Computer. Mac mini costs around 45000 and even mouse cost around 2500. Hope you buy a new Mac and try this. :lol:

Comments

Popular posts from this blog

English Translation of "Voda Voda " song from Mayakam Enna

Hi guys        Too many Tamil post and my Non-Tamil readers would have really bugged up with my previous posts. Many non-tamil people who hear this song "Voda Voda Voda" from Mayakam Enna is wondering what is the exact meaning of this song. They don't know the meaning but still they enjoy it. Now read this post, know the meaning and sing it along.        I have differentiated the original lyrics of the song in blue color and the meaning of it in the next line in red color. Here we go... Voda voda voda thooram korayala... Running running running distance didn't get reduced... Paada paada  paada paatum mudiyala... Singing singing singing song didn't get over... Poga poga poga onum puriyala, aaga motham onum velangala... Time passing by nothing able to grasp, totally nothing understood... Free ah suthum podhu figure illaye... While roaming freely figure was not there... Pudicha figurum ipa free ah illaye... The figure I liked is not free now.. Kayil bat iruku

செந்தாழம் பூவில் வந்தாடும் தென்றல் (Senthazham poovil vandhaadum thendral) song lyrics and meaning

                I am so astonished by the creativity of Kaviyarasu Kannadasan and the language itself. This is one of my favourite song in the tamil movie called Mullum Malarum. Wonderful movie with extraordinary music composition by famous Isaigyaani Ilayaraja sir.                  I will try giving the exact meaning of this song which portrays how beautiful women are and you can relate to anything which comes to your mind when you read it along. Kannadasan , Ilayaraja and K.J.Yesudas , a combination that shouldn't be missed. Song :   Senthaazham poovil vandhaadum thendral Lyrics : Kannadasan Music : Ilayaraja Singer : K.J.Jesudas செந்தாழம் பூவில் வந்தாடும் தென்றல்  என் மீது மொதுதமா.. (x2) பூ வாசம் மேடை போடுதம்மா  பெண் போல ஜாடை பேசுதம்மா.. அம்மம்மா ஆனந்தம்.. அம்மம்மா ஆனந்தம்.. Senthaazham poovil vandhaadum thendral  En meedhu modhudhamaa.. Poo vaasam medai podudhamaa Penn pola jaadai pesudhamma.. Ammammaa aanandham.. ammammaa aanandham.

Rasaali Song Lyrics and Translation - To my best (Achcham Enbadhu Madamaiyada)

          I have tried my best to translate this awesome composition of A.R.Rahman - Rasaali for the movie அச்சம் என்பது மடமையடா (Acham Enbadhu Madamaiyada) which lazy people tend to call it AEM. Tamil is such a beautiful language, its difficult to get the exact ecstasy until you know the language. Divinity at its best.  Movie is not yet released, but I guess the situation is lead actor and actress is going on a bike ride when they sing this song to express their feelings. Credits to lyricist Thamarai. Song :   Rasaali Lyrics : Thamarai Music : A.R.Rahman Singers : Sathya Prakash, Shashaa Tirupati Male: Parakkum rasaaliye rasaaliye nillu.. Ingu nee vegama naan vegama sollu.. Gadigaaram poi sollum endre naan kanden.. Kizhakellam merkaagida.. kandene.. பறக்கும் இராசாலியே இராசாலியே நில்லு.. இங்கு நீ வேகமா நான் வேகமா சொல்லு.. கடிகாரம் பொய் சொல்லும் என்றே நான் கண்டேன்.. கிழக்கெல்லாம் மேற்காகிட.. கண்டேனே.. Flying falcon, please wait..  (Comparing his girl to a