Я пытаюсь сделать вышеупомянутую форму с uikit. Небольшой независимый круг меня не беспокоит, однако, полукруга в нижней части слева от округленного прямоугольного прямоугольника-это то, где я застрял, особенно с учетом границы, и тот факт, что цвет фона имеет 70% альфа-компонент (это означает, что он частично прозрачен.) alt = "Результат наложения двух представлений" src = "https://i.sstatic.net/namqddpn.png"/>
Учитывая, я решил попытаться переопределить функцию рисования Uiview. Вот моя попытка: < /p>
Код: Выделить всё
override func draw(_ rect: CGRect) {
guard let context = UIGraphicsGetCurrentContext() else { return }
let fillColor = configuration.isTransparent
? UIColor.primaryPurple.withAlphaComponent(0.7)
: UIColor.primaryPurple
let width = rect.width
let height = rect.height
let roundedRect = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: width, height: height - 8), cornerRadius: 24)
let circle = UIBezierPath(ovalIn: CGRect(x: 24, y: height - 24, width: 24, height: 24))
// Combine into one path
let combinedPath = UIBezierPath()
combinedPath.append(roundedRect)
combinedPath.append(circle)
combinedPath.usesEvenOddFillRule = false // Important: treat as single shape
// Fill
context.addPath(combinedPath.cgPath)
context.setFillColor(fillColor.cgColor)
context.fillPath()
// Stroke
context.addPath(combinedPath.cgPath)
context.setStrokeColor(UIColor.primaryPurple.cgColor)
context.setLineWidth(1)
context.setLineJoin(.round)
context.strokePath()
}
По правде говоря, я не уверен, куда перейти к
>
Подробнее здесь: https://stackoverflow.com/questions/796 ... t-in-swift
Мобильная версия