【问题标题】:How to apply sharp corner radius with border on UIView in swift?如何快速在 UIView 上应用带有边框的尖角半径?
【发布时间】:2018-05-25 14:53:12
【问题描述】:

我想在 UIView 的边框上设置左下角和右下角的圆角半径。这是代码。 **问题是它不在 1.5 边框中显示 SHARP **

class BorderView: UIView {

  override func draw(_ rect: CGRect) {

    let color = UIColor.red
    let color2 = UIColor.brown

    //// Rectangle Drawing
    let rectanglePath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 200, height: 200), byRoundingCorners: [.bottomRight, .bottomLeft], cornerRadii: CGSize(width: 10, height: 10))
    rectanglePath.close()
    color2.setFill()
    rectanglePath.fill()
    color.set()
    rectanglePath.lineWidth = 1.5
    rectanglePath.stroke()

 }
}

输出

预期输出

【问题讨论】:

  • “尖锐”是指“平滑”还是“尖锐”?
  • 您是否尝试过使用不是分数的线宽?所以要么1要么2
  • 嘿@rmaddy 我想要“顺利”

标签: swift uiview border layer cornerradius


【解决方案1】:

如果您使用CALayer 上的边框和角属性,它应该会为您完成所有工作。

// Probably inside init
layer.borderWidth = 1.5
layer.borderColor = UIColor.red.cgColor

layer.cornerRadius = 10
layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]

【讨论】:

  • 感谢@clever 它的显示“Sharp”和“Smooth” :)
  • 您能帮个忙吗?我想设置边框只有 3 边 Left , Right 和 Bottom 具有锐角半径。
  • 没有选项可以仅在某些边上添加边框。我将视图放置在其父视图内,使顶部高于父视图的顶部,以便边框将被父视图边界剪裁。
猜你喜欢
  • 1970-01-01
  • 2021-09-11
  • 1970-01-01
  • 1970-01-01
  • 2019-12-07
  • 1970-01-01
  • 1970-01-01
  • 2011-10-27
  • 1970-01-01
相关资源
最近更新 更多