[Objc] UIButton with rounded corners (IBInspectable)

APRoundedButton is a simple XIB/Storyboard extension to make rounded custom buttons, without writing one line of code, now using IBInspectable.

What are IBInspectable?

IBInspectable properties provide new access to an old feature: user-defined runtime attributes.
Currently accessible from the identity inspector, these attributes have been available since before
Interface Builder was integrated into Xcode.

They provide a powerful mechanism for configuring any key-value coded property of an instance in a NIB, XIB, or storyboard.

Apple dochttps://developer.apple.com/library/ios/recipes/xcode_help-IB_objects_media/Chapters/CreatingaLiveViewofaCustomObject.html

How to use

Requirements

  • ARC
  • iOS 7+
  • Xcode 5

Copy in your project the files:

[code autolinks=”false” collapse=”false” firstline=”1″ gutter=”true” htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”]APRoundedButton.h
APRoundedButton.m[/code]

and add QuartzCore framework.

Steps:
  • Open your XIB or Storyboard
  • Draw a UIButton
  • Change the default class to APRoundedButton
Available options:
  • Corner TOP LEFT
  • Corner TOP RIGTH
  • Corner BOTTOM LEFT
  • Corner BOTTOM RIGTH
  • Corner RADIUS
  • BUTTON COLOR

You should see “Rounded Button” options.
…try to change and you see in realtime the preview of your corners!

ss

Build and run. That’s all!
No one line of code is needed!

Full project on github: https://github.com/elpsk/APRoundedButton

have fun.


The old one article “UIButton with rounded corners” do the same thing but usingUser-defined Runtime Attributes.

ss-c

Want Android version?
Look here!
http://www.albertopasca.it/whiletrue/android-button-with-rounded-corners/

ref:
albertopasca.it

 

Alberto Pasca

Software engineer @ Pirelli & C. S.p.A. with a strong passion for mobile  development, security, and connected things.