如何在swift中制作如下图像的标签

时间:2017-10-10 08:00:18

标签: swift

我正在研究聊天应用程序,我尝试制作像贝娄图像这样的标签,但我做不到任何人都可以帮助我。

enter image description here

2 个答案:

答案 0 :(得分:1)

在Xcode中转到您的资源,选择您的气泡图片,然后点击show slicing

切片使您的图像能够与给定切片一起拉伸而不会变形。

答案 1 :(得分:-1)

使用CoreGraphics绘制此表单很复杂。我已经实现了这个不完美的结果。你可以在" drawRect"中使用这个代码。方法,并且必须绘制(或覆盖布局)文本。

func drawCanvas1(frame: CGRect = CGRect(x: 0, y: 0, width: 120, height: 100)) {
    //// General Declarations
    // This non-generic function dramatically improves compilation times of complex expressions.
    func fastFloor(_ x: CGFloat) -> CGFloat { return floor(x) }

    //// Rectangle Drawing
    let rectanglePath = UIBezierPath(roundedRect: CGRect(x: frame.minX + fastFloor(frame.width * 0.25000 + 0.5), y: frame.minY + fastFloor(frame.height * 0.00000 + 0.5), width: fastFloor(frame.width * 1.00000 + 0.5) - fastFloor(frame.width * 0.25000 + 0.5), height: fastFloor(frame.height * 1.00000 + 0.5) - fastFloor(frame.height * 0.00000 + 0.5)), cornerRadius: 10)
    UIColor.gray.setFill()
    rectanglePath.fill()


    //// Bezier 3 Drawing
    let bezier3Path = UIBezierPath()
    bezier3Path.move(to: CGPoint(x: frame.minX + 0.5, y: frame.minY + 85.5))
    bezier3Path.addCurve(to: CGPoint(x: frame.minX + 30.5, y: frame.minY + 64.5), controlPoint1: CGPoint(x: frame.minX + 0.5, y: frame.minY + 85.5), controlPoint2: CGPoint(x: frame.minX + 30.5, y: frame.minY + 85.5))
    bezier3Path.addCurve(to: CGPoint(x: frame.minX + 43.5, y: frame.minY + 99.5), controlPoint1: CGPoint(x: frame.minX + 30.5, y: frame.minY + 43.5), controlPoint2: CGPoint(x: frame.minX + 43.5, y: frame.minY + 99.5))
    bezier3Path.move(to: CGPoint(x: frame.minX + 0.59, y: frame.minY + 85.5))
    bezier3Path.addCurve(to: CGPoint(x: frame.minX + 43.5, y: frame.minY + 99.5), controlPoint1: CGPoint(x: frame.minX - 0.43, y: frame.minY + 86.43), controlPoint2: CGPoint(x: frame.minX + 6.72, y: frame.minY + 99.5))
    UIColor.gray.setFill()
    bezier3Path.fill()
    UIColor.gray.setStroke()
    bezier3Path.lineWidth = 1
    bezier3Path.lineCapStyle = .round
    bezier3Path.lineJoinStyle = .round
    bezier3Path.stroke()
}

Result

我建议您使用此表单在Illustrator或其他程序中创建图像,并将其用作背景。