IOSDEV Telegram 1299
Как iOS 18 улучшает работу с градиентами

Очень часто в проектах разработчики используют дополнительный градиент, чтобы создать контраст между фоном и текстом.
*Или используют заранее заготовленный ассет в каталоге ресурсов.

Однако при таком использовании линейного градиента будут видны перепады яркости и резкий переход.

📖 В iOS 18 доступно новое API для смешивания цветов. Поэтому, используя UnitCurve, можно интерполировать цвета с помощью встроенных или кастомных кривых Безье, чтобы обеспечить плавность перехода.

Пример использования под катом (разверните, чтобы посмотреть):
extension Gradient {
init(from: Color, to:Color, with curve:UnitCurve, steps:Int = 10) {
let colors = stride(from: 0.0, through: 1.0, by: 1.0 / Double(steps))
.map { f in
from.mix(with: to, by: curve.value(at: f))
}
self.init(colors: colors)
}
}


📖 Почитать дополнительно про смешивание цветов можно в этой статье.

😃 iOS Devбольше разборов тут
Please open Telegram to view this post
VIEW IN TELEGRAM
22👍5🔥4❤‍🔥21👏1💯1🏆1🤗1🎄1



tgoop.com/iosdev/1299
Create:
Last Update:

Как iOS 18 улучшает работу с градиентами

Очень часто в проектах разработчики используют дополнительный градиент, чтобы создать контраст между фоном и текстом.
*Или используют заранее заготовленный ассет в каталоге ресурсов.

Однако при таком использовании линейного градиента будут видны перепады яркости и резкий переход.

📖 В iOS 18 доступно новое API для смешивания цветов. Поэтому, используя UnitCurve, можно интерполировать цвета с помощью встроенных или кастомных кривых Безье, чтобы обеспечить плавность перехода.

Пример использования под катом (разверните, чтобы посмотреть):

extension Gradient {
init(from: Color, to:Color, with curve:UnitCurve, steps:Int = 10) {
let colors = stride(from: 0.0, through: 1.0, by: 1.0 / Double(steps))
.map { f in
from.mix(with: to, by: curve.value(at: f))
}
self.init(colors: colors)
}
}


📖 Почитать дополнительно про смешивание цветов можно в этой статье.

😃 iOS Devбольше разборов тут

BY iOS Dev




Share with your friend now:
tgoop.com/iosdev/1299

View MORE
Open in Telegram


Telegram News

Date: |

Among the requests, the Brazilian electoral Court wanted to know if they could obtain data on the origins of malicious content posted on the platform. According to the TSE, this would enable the authorities to track false content and identify the user responsible for publishing it in the first place. How to create a business channel on Telegram? (Tutorial) Users are more open to new information on workdays rather than weekends. Ng was convicted in April for conspiracy to incite a riot, public nuisance, arson, criminal damage, manufacturing of explosives, administering poison and wounding with intent to do grievous bodily harm between October 2019 and June 2020. The creator of the channel becomes its administrator by default. If you need help managing your channel, you can add more administrators from your subscriber base. You can provide each admin with limited or full rights to manage the channel. For example, you can allow an administrator to publish and edit content while withholding the right to add new subscribers.
from us


Telegram iOS Dev
FROM American