2016-09-22 62 views
0

enter image description hereiOS按钮设计

设计自定义按钮并在Xcode中使用它们的最佳方式是什么?我希望他们不要看起来像随机按钮。它们应该像苹果公司自己的按钮一样。

+0

我更新了我的问题。这是我到目前为止的尝试,但它不适合很好的设计元素... –

+0

使用标准UIButton有什么问题? – rmaddy

+0

我想让我的按钮脱颖而出 –

回答

1

您可以只使用的UIButton,您可以设置容易:

  • 背景颜色,背景图像
  • 字体类型,字体颜色
  • 圆角甚至
  • 尺寸与动力正确约束

你想要什么样的按钮?科?同时参阅this link的基本教程。

1

创建一个名为design.swift然后将这些新文件:

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 
     } 
    } 
} 

然后点击您的按钮去上课的权利自定义