Reputation: 43
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
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
Reputation: 4906
You can use just the UIButton, you can set easily:
What kind of button do you want to make? See this link for a basic tutorial meantime.
Upvotes: 1