ios - Custom UIButton Class for Reuse -


been looking online while , haven't gotten straight answer on how done.

in app need "next" button reside on many viewcontrollers. want next button same (bordered, same background color, same custom font, same font size, same button size).

//next button properties [self.nextbuttonoutlet setframe:cgrectmake(120, 454, 80, 30)]; [[self.nextbuttonoutlet layer] setborderwidth:2.0f]; [[self.nextbuttonoutlet layer] setbordercolor:uicolorfromrgb(0xbbffd6).cgcolor]; self.nextbuttonoutlet.titlelabel.font = [uifont fontwithname:@"gothamrnd-light" size:22.0]; [self.nextbuttonoutlet settitle:@"next" forstate:uicontrolstatenormal]; [self.nextbuttonoutlet setbackgroundcolor:uicolorfromrgb(0x72ce97)]; [self.nextbuttonoutlet settitlecolor:uicolorfromrgb(0xbbffd6) forstate:uicontrolstatenormal]; 

it seems silly code in every view controller.

anyone have solution this?

you can create extension uibutton , add new method returns custom uibutton.

in objective-c:

+ (uibutton *)nextbutton {     // create , return button here } 

or in swift:

extension uibutton {     class func nextbutton() -> uibutton {         // create , return button here       return nextbutton()     } } 

then create using:

uibutton.nextbutton() 

Comments

Popular posts from this blog

java - JavaScript + Thymeleaf - select onchange -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

node.js - Using Node without global install -