iOS Creating a UIButton


UIButtons can be initialized in a frame:


let button = UIButton(frame: CGRect(x: x, y: y, width: width, height: height)

Objective C

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(x, y, width, height)];

A specific type of UIButton can be created like this:


let button = UIButton(type: .Custom) 

Objective C

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

where type is a UIButtonType:

enum UIButtonType : Int {
    case Custom
    case System
    case DetailDisclosure
    case InfoLight
    case InfoDark
    case ContactAdd
    static var RoundedRect: UIButtonType { get }