我在检查器中看到我可以改变背景颜色,但是我想改变边框的颜色和粗细,可以吗?


当前回答

swift 4.2中项目的边框颜色:

let cell = tableView.dequeueReusableCell(withIdentifier: "Cell_lastOrderId") as! Cell_lastOrder
cell.layer.borderWidth = 1
cell.layer.borderColor = UIColor.white.cgColor
cell.layer.cornerRadius = 10

其他回答

你也可以创建边界的颜色你的愿望..

view.layer.borderColor = [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0].CGColor;

*r,g,b是0到255之间的值。

view.layer.borderWidth = 1.0
view.layer.borderColor = UIColor.lightGray.cgColor

在UIView扩展中添加以下@IBInspectables

extension UIView {

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

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

然后你应该能够从属性检查器中直接设置borderColor和borderWidth属性。见附图

属性检查器

你需要使用视图层来设置边界属性。例句:

#import <QuartzCore/QuartzCore.h>
...
view.layer.borderColor = [UIColor redColor].CGColor;
view.layer.borderWidth = 3.0f;

你还需要链接到QuartzCore.framework来访问这个功能。

swift 4.2中项目的边框颜色:

let cell = tableView.dequeueReusableCell(withIdentifier: "Cell_lastOrderId") as! Cell_lastOrder
cell.layer.borderWidth = 1
cell.layer.borderColor = UIColor.white.cgColor
cell.layer.cornerRadius = 10