Skip to content

Commit

Permalink
添加太空人小组件
Browse files Browse the repository at this point in the history
  • Loading branch information
yoiuerw committed Feb 13, 2024
1 parent fe21a30 commit a8dd1f6
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 15 deletions.
6 changes: 6 additions & 0 deletions DouYinCComment/DouYinCComment.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
790B62D02B7B811000CE4993 /* 03.png in Resources */ = {isa = PBXBuildFile; fileRef = 790B62B52B7B811000CE4993 /* 03.png */; };
790B62D12B7B811000CE4993 /* 09.png in Resources */ = {isa = PBXBuildFile; fileRef = 790B62B62B7B811000CE4993 /* 09.png */; };
790B62D22B7B811000CE4993 /* 09.png in Resources */ = {isa = PBXBuildFile; fileRef = 790B62B62B7B811000CE4993 /* 09.png */; };
790B62D42B7BCCA900CE4993 /* spaceman_astronaut.otf in Resources */ = {isa = PBXBuildFile; fileRef = 790B62D32B7BCCA900CE4993 /* spaceman_astronaut.otf */; };
790B62D52B7BCCA900CE4993 /* spaceman_astronaut.otf in Resources */ = {isa = PBXBuildFile; fileRef = 790B62D32B7BCCA900CE4993 /* spaceman_astronaut.otf */; };
790F14D9225CF98F000E7335 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 790F14D8225CF98F000E7335 /* AppDelegate.m */; };
790F14DF225CF98F000E7335 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 790F14DD225CF98F000E7335 /* Main.storyboard */; };
790F14E1225CF991000E7335 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 790F14E0225CF991000E7335 /* Assets.xcassets */; };
Expand Down Expand Up @@ -595,6 +597,7 @@
790B62B42B7B810F00CE4993 /* 1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 1.png; sourceTree = "<group>"; };
790B62B52B7B811000CE4993 /* 03.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 03.png; sourceTree = "<group>"; };
790B62B62B7B811000CE4993 /* 09.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 09.png; sourceTree = "<group>"; };
790B62D32B7BCCA900CE4993 /* spaceman_astronaut.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = spaceman_astronaut.otf; sourceTree = "<group>"; };
790F14D4225CF98F000E7335 /* DouYinCComment.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DouYinCComment.app; sourceTree = BUILT_PRODUCTS_DIR; };
790F14D7225CF98F000E7335 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
790F14D8225CF98F000E7335 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1382,6 +1385,7 @@
790B627B2B7A4E4000CE4993 /* TreeNewBee24.ttf */,
790B62822B7A4E4300CE4993 /* TreeNewBee30.ttf */,
790B627F2B7A4E4100CE4993 /* TreeNewBee60.ttf */,
790B62D32B7BCCA900CE4993 /* spaceman_astronaut.otf */,
790B62B42B7B810F00CE4993 /* 1.png */,
790B62AD2B7B810D00CE4993 /* 01.png */,
790B62AA2B7B810C00CE4993 /* 2.png */,
Expand Down Expand Up @@ -2738,6 +2742,7 @@
790B62D02B7B811000CE4993 /* 03.png in Resources */,
33BF7EF428FB26CC00CA4292 /* Assets.xcassets in Resources */,
790B62C22B7B811000CE4993 /* 06.png in Resources */,
790B62D52B7BCCA900CE4993 /* spaceman_astronaut.otf in Resources */,
790B62C62B7B811000CE4993 /* 07.png in Resources */,
790B62BE2B7B811000CE4993 /* 05.png in Resources */,
790B62C82B7B811000CE4993 /* 4.png in Resources */,
Expand Down Expand Up @@ -2793,6 +2798,7 @@
790B629E2B7A4E4500CE4993 /* TreeNewBee3.ttf in Resources */,
790B62882B7A4E4400CE4993 /* TreeNewBee8.ttf in Resources */,
793D5D0B26C0135F00DFC4FB /* MJRefresh.bundle in Resources */,
790B62D42B7BCCA900CE4993 /* spaceman_astronaut.otf in Resources */,
790B62962B7A4E4500CE4993 /* TreeNewBee6.ttf in Resources */,
790B629A2B7A4E4500CE4993 /* TreeNewBee15.ttf in Resources */,
790F14DF225CF98F000E7335 /* Main.storyboard in Resources */,
Expand Down
1 change: 1 addition & 0 deletions DouYinCComment/DouYinCComment/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<dict>
<key>UIAppFonts</key>
<array>
<string>spaceman_astronaut.otf</string>
<string>TreeNewBee2.ttf</string>
<string>TreeNewBee3.ttf</string>
<string>TreeNewBee4.ttf</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,92 @@
//

import SwiftUI

@available(iOS 15.0, *)
struct WidgetFrameAniView: View {
var frameImages:[String] = []
var date: Date = Date()
var body: some View {

GeometryReader { geo in
ZStack() {

var minSize = geo.size.width > geo.size.height ? geo.size.height : geo.size.width
ForEach(frameImages.indices, id: \.self) { index in

let imagePath = Bundle.main.path(forResource: frameImages[index], ofType: "png")
let image = UIImage(contentsOfFile: imagePath ?? "")
// let image = UIImage(named: frameImages[index])
// let image = UIImage(named: frameImages[index])
let imageDate = Date(timeInterval: TimeInterval(index - frameImages.count), since: date)
Image(uiImage:image ?? UIImage())
.resizable()
.scaledToFit()
.mask(alignment: .center)
.mask(alignment: .trailing)
{
Text(imageDate, style: .timer)
.multilineTextAlignment(.center)
.multilineTextAlignment(.trailing)
.font(.custom("TreeNewBee\(frameImages.count)", size: minSize))
.foregroundColor(Color.black)
.offset(x: -minSize/2)
.frame(width: minSize * 2, height: minSize, alignment: .center)
// .offset(x: -minSize/2)
.frame(width: minSize * 5, height: minSize, alignment: .trailing)
}
// .frame(width: minSize,height: minSize)
// .frame(width: minSize,height: minSize)
// .contentTransition(.identity)
.clipped()
}


}
.position(CGPoint(x: geo.size.width/2, y: geo.size.height/2))

}

}
}





@available(iOS 14.0, *)
struct WidgetFrameAniView2: View {
var color : Color = .white
var body: some View {
GeometryReader { geo in
var minSize = geo.size.width > geo.size.height ? geo.size.height : geo.size.width
ZStack(alignment: .trailing) {
Text(Date(), style: .timer)
.multilineTextAlignment(.trailing)
.font(.custom("spaceman_astronaut", size: minSize))
.foregroundColor(color)
// .background(Color.green)
.frame(width: minSize * 5, height: minSize, alignment: .trailing)
// .clipped()
}
.frame(width: minSize, height: minSize,alignment: .trailing)
.clipped()
// .background(Color.red)
.position(CGPoint(x: geo.size.width/2, y: geo.size.height/2))

}
}
}



//@available(iOS 14.0, *)
//struct ContentView11: View {
// var body: some View {
// GeometryReader { geo in
// ZStack(alignment: .trailing) {
// Text(Date(), style: .timer)
// //.fixedSize() // ,如果是普通Text文本,加上这个的作用就是文本过长不显示...,直接截断, 那么其实就没必要把宽度弄成2千,但是在倒计时上加上这次直接数字就不显示了.所以没法用
// .multilineTextAlignment(.trailing)
// .foregroundColor(Color.orange)
// .lineLimit(1)
// .font(.custom("spaceman_astronaut", size: geo.size.height))
// .frame(width: 2000, height: geo.size.height, alignment: .trailing)
// .background(Color.red)
//
// }
// .frame(maxWidth: geo.size.width, maxHeight: geo.size.height,alignment: .trailing)
// .background(Color.green)
// .clipped()
// }
// .background(Color.purple)
// }
//}
Binary file not shown.
17 changes: 16 additions & 1 deletion DouYinCComment/DouYinCComment/WidgetSwift/WidgetSwiftView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,24 @@ import WidgetKit


}



if #available(iOS 14.0, *) {
var vc8 = UIHostingController(rootView:WidgetFrameAniView2(color: .white))
vc8.view.backgroundColor = UIColor.black
vc8.view.layer.cornerRadius = 22;
vc8.view.layer.masksToBounds = true;
scrolV.addSubview(vc8.view)
vc8.view.frame = CGRectMake(180, 530, 80, 80)

var vc9 = UIHostingController(rootView:WidgetFrameAniView2(color: .red))
vc9.view.backgroundColor = UIColor.black
vc9.view.layer.cornerRadius = 22;
vc9.view.layer.masksToBounds = true;
scrolV.addSubview(vc9.view)
vc9.view.frame = CGRectMake(270, 530, 80, 80)

}


}
Expand Down
1 change: 1 addition & 0 deletions DouYinCComment/RecommendWidget/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<dict>
<key>UIAppFonts</key>
<array>
<string>spaceman_astronaut.otf</string>
<string>TreeNewBee2.ttf</string>
<string>TreeNewBee3.ttf</string>
<string>TreeNewBee4.ttf</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ extension FrameAniWidget {

var body: some View {
if #available(iOS 15.0, *) {
WidgetFrameAniView(frameImages: ["01","02","03","04","05","06","07","08","09","010"])

switch family {
case .systemSmall: WidgetFrameAniView(frameImages: ["01","02","03","04","05","06","07","08","09","010"])
case .systemMedium: WidgetFrameAniView2(color: .red)
default: WidgetFrameAniView(frameImages: ["01","02","03","04","05","06","07","08","09","010"])
}


} else {
Text("123")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct FrameAniWidget: Widget {
}
.configurationDisplayName("帧动画")
.description("帧动画小组件,有需要代码自拿")
.supportedFamilies([.systemSmall])
.supportedFamilies([.systemSmall, .systemMedium])
.ddcontentMarginsDisabled()
}
}

0 comments on commit a8dd1f6

Please sign in to comment.