Aman Kumar Aman Kumar - 1 year ago 151
Swift Question

Swift - Round Button

I want to create several round buttons in swift, with collision detection and gravity acting on them. But whenever I do so, during collision they acts as a square, (I've tried adding image to button or by creating it through code but the result remains the same), so can anyone help as I want to create round buttons that acts like round shape whenever they collide or fall.

Answer Source

Try OBShapedButton

this one is third party class available for different shape type buttons and button created with this class acts as shape of image you have given to button.

To use this in storyboard or xib file just give Custom Class as OBShapedButton to UIButton.

or programmatically

obj_OBShapedButton = [OBShapedButton buttonWithType:UIButtonTypeCustom];
[obj_OBShapedButton setFrame:CGRectMake(10, 10, 160,161)];

[obj_OBShapedButton setImage:[UIImage imageNamed:@"button-normal.png"] forState:UIControlStateNormal];
[obj_OBShapedButton addTarget:self action:@selector(Buton_action) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:obj_OBShapedButton];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download