Repaz Kung
Repaz Kung

Reputation: 43

iOS button design

enter image description here

What is the best way to design custom buttons and using them within Xcode. I want them not to look like random buttons. They should look like button as the were from Apple themselves.

Upvotes: 0

Views: 1065

Answers (2)

Soul
Soul

Reputation: 50

Create a new file called design.swift then add these:

import Foundation
import UIKit

@IBDesignable class CustomTextView : UITextView
{

    @IBInspectable var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0
        }
    }


    @IBInspectable var borderWidth: CGFloat{
        set {
            layer.borderWidth = newValue
        }
        get{
            return self.layer.borderWidth
        }
    }

    @IBInspectable var borderColor: UIColor? {
        set {
            layer.borderColor = newValue?.CGColor
        }
        get{
            let c = UIColor(CGColor: layer.borderColor!)
            return c
        }
    }

}

@IBDesignable class CustomView : UIView{

    @IBInspectable var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0
        }
    }



    @IBInspectable var borderWidth: CGFloat{
        set {
            layer.borderWidth = newValue
        }
        get{
            return self.layer.borderWidth
        }
    }

    @IBInspectable var borderColor: UIColor? {
        set {
            layer.borderColor = newValue?.CGColor
        }
        get{
            let c = UIColor(CGColor: layer.borderColor!)
            return c
        }
    }
}



@IBDesignable class CustomButton : UIButton{

    @IBInspectable var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0
        }
    }



    @IBInspectable var borderWidth: CGFloat{
        set {
            layer.borderWidth = newValue
        }
        get{
            return self.layer.borderWidth
        }
    }

    @IBInspectable var borderColor: UIColor? {
        set {
            layer.borderColor = newValue?.CGColor
        }
        get{
            let c = UIColor(CGColor: layer.borderColor!)
            return c
        }
    }
}

then click at your button go to class right Custom

Upvotes: 1

Massimo Polimeni
Massimo Polimeni

Reputation: 4906

You can use just the UIButton, you can set easily:

  • background color, background image
  • font type, font color
  • round corner
  • dimensions even dynamics with the right constraints

What kind of button do you want to make? See this link for a basic tutorial meantime.

Upvotes: 1

Related Questions