怎么在iOS中利用SwiftUI實(shí)現(xiàn)顏色漸變填充效果-創(chuàng)新互聯(lián)

這篇文章給大家介紹怎么在iOS中利用SwiftUI實(shí)現(xiàn)顏色漸變填充效果,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

成都創(chuàng)新互聯(lián)公司專注于臨桂網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供臨桂營(yíng)銷型網(wǎng)站建設(shè),臨桂網(wǎng)站制作、臨桂網(wǎng)頁(yè)設(shè)計(jì)、臨桂網(wǎng)站官網(wǎng)定制、微信小程序開發(fā)服務(wù),打造臨桂網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供臨桂網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。

Gradient 漸變器

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

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

LinearGradient 線性漸變器

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

import SwiftUI

struct 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 SwiftUI

struct 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 徑向漸變

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

import SwiftUI

struct 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

在角漸變中,我們只需要通過中心點(diǎn)。

import SwiftUI

struct 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)
     }
   }

關(guān)于怎么在iOS中利用SwiftUI實(shí)現(xiàn)顏色漸變填充效果就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站muchs.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

新聞名稱:怎么在iOS中利用SwiftUI實(shí)現(xiàn)顏色漸變填充效果-創(chuàng)新互聯(lián)
標(biāo)題網(wǎng)址:http://muchs.cn/article20/dsodjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、面包屑導(dǎo)航、云服務(wù)器網(wǎng)站制作、網(wǎng)站內(nèi)鏈、做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)