Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a circle in xib for interface builder

I've been drawing my circles using Core Graphics, but I have recently started implementing xibs using the interface builder for my views. Is there anyway to draw a circle using the interface builder? Surprisingly, I couldn't find any other thread answering this question even though it sounds like a simple one.

like image 475
zaloo Avatar asked Feb 02 '14 01:02

zaloo


1 Answers

There isn't per-se, but you can achieve this effect using a view's corner radius. This is performance-heavy however, so you should test on different devices and see the performance implications of this.

Xcode provides a "User Defined Runtime Attributes" section:

User Defined Runtime Attributes

The format of this is key path and value.

You could set the layer.cornerRadius keypath to half the width/height of the view. To help with performance, you can set the layer.shouldRasterize key path to YES.

like image 190
Léo Natan Avatar answered Nov 14 '22 23:11

Léo Natan