国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS SwiftUI 顏色漸變填充效果的實現(xiàn)

2020-07-26 02:18:16
字體:
來源:轉載
供稿:網友

SwiftUI 為我們提供了各種梯度選項,所有這些選項都可以通過多種方式使用。

Gradient 漸變器

A color gradient represented as an array of color stops, each having a parametric location value.

gradient是一組顏色的合集,每個顏色都忽略位置參數(shù)

LinearGradient 線性漸變器

線性漸變器擁有沿軸進行漸變函數(shù),我們可以自定義設置顏色空間、起點和終點。

下面我們看看LinearGradient效果

import SwiftUIstruct LineView: View {   var gradient: Gradient {      let stops: [Gradient.Stop] = [        .init(color: .red, location: 0.5),        .init(color: .yellow, location: 0.5)      ]      return Gradient(stops: stops)    }        var body: some View {            ZStack {          LinearGradient(gradient: gradient,                 startPoint: .top,                 endPoint: .trailing)            .edgesIgnoringSafeArea(.all)                    Image("1")            .resizable()            .aspectRatio(contentMode: .fit)            .clipShape(Circle())            .overlay(Circle()              .stroke(lineWidth: 8)              .foregroundColor(.white))            .frame(width: 250)                  Text("洛神賦圖")              .padding()              .foregroundColor(.white)          .cornerRadius(8)              .background(LinearGradient(gradient: Gradient(colors: [.white, .black]), startPoint: .top, endPoint: .bottom))          .offset(y:-280)        }    }}

import SwiftUIstruct LineGradient3Color: View {    var body: some View {    ZStack {      LinearGradient(gradient:        Gradient(          colors: [.blue, .white, .pink]),              startPoint: .topLeading,              endPoint: .bottomTrailing)        .edgesIgnoringSafeArea(.all)            Image("2")        .resizable()        .aspectRatio(contentMode: .fit)        .clipShape(Circle())        .overlay(Circle()          .stroke(lineWidth: 8)          .foregroundColor(.white))        .frame(width: 250)            Text("清明上河圖")        .padding()        .foregroundColor(.white)        .cornerRadius(8)        .background(LinearGradient(gradient: Gradient(          colors: [.yellow, .red]),                      startPoint: .topLeading,          endPoint: .bottomTrailing))        .offset(y:-180)    }  }}

Radial Gradient 徑向漸變

在徑向漸變中,我們必須指定起始半徑點,端半徑點與中心點,從徑向漸變開變.

import SwiftUIstruct RadialView: View {   var body: some View {     ZStack {       RadialGradient(gradient: Gradient(        colors: [.blue, .black]),        center: .center,        startRadius: 2,        endRadius: 650)         .edgesIgnoringSafeArea(.all)              Image("3")         .resizable()         .aspectRatio(contentMode: .fit)         .clipShape(Circle())         .overlay(Circle()           .stroke(lineWidth: 8)           .foregroundColor(.white))         .frame(width: 250)              Text("富春山居圖")         .padding()         .foregroundColor(.white)         .cornerRadius(8)         .background(          RadialGradient(gradient: Gradient(           colors: [.yellow, .red]),                  center: .center,                   startRadius: 2,               endRadius: 60))         .offset(y:-180)     }   }}

Angular Gradient

在角漸變中,我們只需要通過中心點。

import SwiftUIstruct AngularView: View {    var body: some View {     ZStack {      AngularGradient(gradient: Gradient(        colors: [.green, .blue, .black, .green, .blue, .black, .green]),        center: .center)         .edgesIgnoringSafeArea(.all)              Image("4")         .resizable()         .aspectRatio(contentMode: .fit)         .clipShape(Circle())         .overlay(Circle()           .stroke(lineWidth: 8)           .foregroundColor(.white))         .frame(width: 250)              Text("漢宮春曉圖")         .padding()         .foregroundColor(.white)         .cornerRadius(8)         .background(          RadialGradient(gradient: Gradient(           colors: [.yellow, .red]),                 center: .center,                   startRadius: 2,              endRadius: 60))         .offset(y:-180)     }   }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 金山区| 平罗县| 若尔盖县| 平和县| 平度市| 平阴县| 彩票| 迁安市| 遂宁市| 永昌县| 阿尔山市| 临泽县| 灵川县| 隆化县| 湟源县| 麻江县| 庆云县| 军事| 贡山| 万载县| 大兴区| 南华县| 广宗县| 确山县| 思南县| 绍兴市| 京山县| 栾城县| 乡城县| 新建县| 霍山县| 泸溪县| 东光县| 大足县| 孝感市| 扎囊县| 海原县| 嘉荫县| 图木舒克市| 志丹县| 宽甸|