iReddy iReddy - 1 year ago 204
Objective-C Question

How to create Diamond shape Button using Objective-C iOS

I need to design diamond shape buttons like below image. I have tried with two

and I'm able to draw diamond shape on top of the views by subclassing the
.But the problem is these two views are overlapping..!

Here is the method i have used :

- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 4.0);
[UIColor blueColor].CGColor);
CGContextMoveToPoint(context, 100, 100);
CGContextAddLineToPoint(context, 150, 150);
CGContextAddLineToPoint(context, 100, 200);
CGContextAddLineToPoint(context, 50, 150);
CGContextAddLineToPoint(context, 100, 100);

enter image description here

Answer Source

You can easily transform a square to a diamond. Assuming that you have a sqaure button called diamond the transfomation below results in a diamond.

CGAffineTransform tr = CGAffineTransformIdentity;
tr = CGAffineTransformScale(tr, 0.8, 1);
tr = CGAffineTransformRotate(tr, M_PI_4);
self.diamond.transform = tr;

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download