Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing Rectangles in iOS

My goal for my app is for the user to be able to sort through different scheduling options by swiping to the left and right of an iPhone screen. How would I draw and remove rectangles as the user sorts through these different scheduling options?

I have a UIViewController.h, UIViewController.m, and UIViewController.xib files to manipulate. Do I need a separate UIView class? If so, how do I connect that UIView class to the view in my .xib file?

like image 479
Bryce Langlotz Avatar asked Feb 09 '13 05:02

Bryce Langlotz


People also ask

What is drawRect?

The drawRect method draws a rectangle outline for the given position and size. We use the graphics context's current color to draw the rectangle's outline color.


2 Answers

You can draw a rectangle by using this:

 UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(68, 38, 81, 40)];
 [UIColor.grayColor setFill];
 [rectanglePath fill];
like image 116
Teja Nandamuri Avatar answered Oct 16 '22 08:10

Teja Nandamuri


Wow... so many complicated solution, here is what you need:

UIView *myBox  = [[UIView alloc] initWithFrame:CGRectMake(180, 35, 10, 10)];
myBox.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:myBox];

Nothing else... don't need to go crazy on the implementation.

like image 27
Wilson Soethe Cursino Avatar answered Oct 16 '22 07:10

Wilson Soethe Cursino