【问题标题】:How to draw Custom UIView in ios?如何在 ios 中绘制自定义 UIView?
【发布时间】:2017-02-07 17:34:09
【问题描述】:

如何绘制自定义视图,如图所示。 我想在主视图中画一个小矩形。

如果有,请参考任何链接。

图片

谢谢

【问题讨论】:

    标签: ios iphone uiview


    【解决方案1】:

    可以像下面这样简单

    import UIKit
    
    class Rectangle:UIView{
    
        override func draw(_ rect: CGRect) {
            let path = UIBezierPath(rect: rect)
            path.move(to: CGPoint(x:0,y:rect.height))
            path.addLine(to: CGPoint(x:rect.width/2,y:rect.height/1.4))
            path.addLine(to: CGPoint(x:rect.width,y:rect.height))
            UIColor.red.setStroke()
            path.stroke()
        }
    
    }
    
    let rect=Rectangle(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
    

    【讨论】:

    • 谢谢,但是你能不能给我Objective c?
    • 这个解决方案是不完整的,除了创建一个UIBezierPath之外实际上并没有绘制任何东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多