today I implemented the new UI what you can see here in the red circle on the #Fix image. Before that the screen looked like the #Old Screen without Feature. But with the new UI element I have now a padding from the map to the name of the store. I have tried many things and researched many things, but in the meantime I have been working on it for a week without success.
#FIX Image
#Old Screen (Result should be like this)
The Code
var body: some View {
VStack(spacing: 0) {
shopModel.logo
.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxWidth: 200, maxHeight: 100)
.padding([.top, .leading, .trailing])
Text(shopModel.name)
.fontWeight(.bold)
.padding()
CustomerCardPoints()
ZStack(alignment: .bottomTrailing) {
MapView()
.frame(height: isMapInFront ? 250 : 100)
.frame(maxWidth: isMapInFront ? .infinity : 100 )
.zIndex(isMapInFront ? 0 : 1)
.cornerRadius(isMapInFront ? 0 : 10)
.padding(isMapInFront ? 0 : 10)
.onTapGesture {
if !isMapInFront {
withAnimation {
isMapInFront.toggle()
}
} else {
let url = URL(string: "maps://?saddr=&daddr=\(shopModel.pinLocation.latitude),\(shopModel.pinLocation.longitude)")
if UIApplication.shared.canOpenURL(url!) {
UIApplication.shared.open(url!, options: [:], completionHandler: nil)
}
}
}
The Struct:
struct CustomerCardPoints: View {
var body: some View {
// Responsiv on iPhone + Pro
// iPhone Max is not implemented
VStack(spacing: 0){
ZStack() {
Image("Slice")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxWidth: 180, maxHeight: 60)
.offset(x: 160, y: -127)
HStack(alignment: .firstTextBaseline) {
Text("22")
.font(.system(size: 18))
.fontWeight(.bold)
.foregroundColor(.white)
.offset(x: 233, y: -126)
Image("favoriten")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 110, height: 25)
.contentShape(Rectangle())
.offset(x: 132, y: -120)
}
}
.onTapGesture {
print("Hier kommt die Navigation zur Customer Card")
}
}
}
}
I tried to unwrap / wrap the Struct in the view so the alignment would be different, but I rather destroyed the code as being closer to the result.
Related
Here is my code:
import SwiftUI
struct TrendingView : View {
#State var selectedTab: Tabs = .hot
#State private var searchText = ""
var body: some View {
NavigationView {
VStack {
HStack {
Text(" Trending")
.font(.largeTitle)
.frame(width: 175, height: 50, alignment: .leading)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(.black, lineWidth: 2)
)
.italic()
.fontWeight(.heavy)
.foregroundColor(Color(hue: 1.0, saturation: 0.977, brightness: 0.985))
.offset(x: -75, y: -25)
.padding(.bottom, -20)
NavigationLink(destination: testT()) {
Image(systemName: "magnifyingglass.circle.fill")
.resizable()
.scaledToFit()
.frame(width: 40, height: 40)
.foregroundColor(.black)
.padding(.bottom, -20)
}
.offset(x: 50, y: -25)
.padding(.leading, 5.0)
}
ScrollView {
VStack {
Text("Hot Items 🔥")
.bold()
.italic()
.offset(x: 5)
.frame(width: 120, height: 25, alignment: .leading)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(.black, lineWidth: 2)
)
.background(.yellow)
.offset(x: -130, y: 5)
ScrollView(.horizontal) {
HStack {
NavigationLink(destination: ImageTest()) {
Image("testpic1")
.resizable()
.frame(width: 200, height: 200)
}
NavigationLink(destination: ImageTest()) {
Image("testpic3")
.resizable()
.frame(width: 200, height: 200)
}
}.offset(y: 30)
}
}
}
There seems to be some error with scrollview above my vstack as it randomly causes all the content on this view to shift downwards when switching to and from other views.Ive tried removing the scrollview and the error disappears and also tried changing it around in other places but I still get the error Can anybody point me in the right direction? Thanks
Fixed, added to the bottom of my code and it seems like the issue is solved
.navigationBarTitle(Text(""), displayMode: .inline)
.navigationBarHidden(true)
Main View Code , My Subview CodeMy CardView is in ZStack and, when stretching the background image, didn't select in the right way a GridView in Main View here is my codes of main and subview
ScrollView {
NavigationLink("", destination: CardCategoryView(cardCategoryVm: .init(card: cardsVm.selectedCard)), isActive: $cardsVm.isShowingCardCategory)
LazyVGrid(columns: gridColoumns,spacing: 8) {
ForEach(cardsVm.cards?.vendor ?? [] ,id: \.self) { symbol in
StoreCardView(image: symbol.image ?? "")
.frame(width: UIScreen.main.bounds.width / 2 - 20,height: UIScreen.main.bounds.width / 2 - 20)
.padding(.top)
.onTapGesture {
let _ = print(symbol.name)
cardsVm.selectedCard = symbol
cardsVm.isShowingCardCategory = true
}
}
}
}
struct StoreCardView: View {
var image:String
var body: some View {
GeometryReader { reader in
ZStack{
KFImage(URL(string:image))
.resizable()
.scaleEffect(x: 3, y: 3, anchor: .center)
.aspectRatio(contentMode: .fit)
.frame(width: reader.size.width , height: reader.size.height , alignment: .center)
.clipped()
.blur(radius: 25, opaque: true)
.opacity(0.7)
.cornerRadius(8)
KFImage(URL(string:image))
.resizable()
.aspectRatio( contentMode: .fill)
.frame(width: reader.size.width/2, height: reader.size.height/2, alignment: .center)
.clipShape(Circle())
.shadow(color: .movColor.opacity(0.4),radius: 5,
x: 0,
y: 0
)
//
} .fixedSize(horizontal: true, vertical: true)
.frame(width: reader.size.width, height: reader.size.height, alignment: .center)
.clipped()
}
}
}
I made it in Ztack and gave it a fixed frame with Scale Effect and it didn't work also, how can I make the background image stretching and didn't effect on gridview at main view
I am rewriting the existing UIKit cell using SwiftUI. The problem is Spacer() cuts Text() and shows less text than the UIKit version (Ethereum C... vs Ethere...). The goal is to have the graph always in the same position in all cells and show more symbols in Text().
var body: some View {
VStack(alignment: .center) {
ZStack {
HStack(spacing: .designSystem(.small)) {
KFImage(viewModel.tradable.logoURL)
.serialize(by: SVGCacheSerializer())
.setProcessor(SVGProcessor())
.scaleFactor(Layout.scaleFactor)
.resizable()
.placeholder {
Circle()
.fill(Color(viewModel.tradable.placeholderColor == nil ? .gray : UIColor(hex: viewModel.tradable.placeholderColor!)))
}
.frame(width: Layout.imageWidth, height: Layout.imageHeight)
.clipShape(RoundedRectangle(cornerRadius: Layout.imageWidth / 2))
.overlay(RoundedRectangle(cornerRadius: Layout.imageWidth / 2).stroke(.white, lineWidth: 2 / UIScreen.main.scale))
VStack(alignment: .leading, spacing: .designSystem(.extraSmall3)) {
Text(viewModel.name).font(.subheadline).fontWeight(.semibold).lineLimit(1)
Text(viewModel.symbol).font(.caption2).foregroundColor(Color(ThemeManager.current.neutral50))
}
Spacer()
AssetLineChartViewRepresentable(viewModel: chartViewModel).frame(width: 65, height: 20)
Spacer()
VStack(alignment: .trailing, spacing: .designSystem(.extraSmall3)) {
percentChangeView(assetPercentChangeType: viewModel.assetPercentChangeType)
Text(viewModel.priceString).font(.caption2).foregroundColor(Color(ThemeManager.current.neutral50))
}
}
.padding([.leading, .trailing])
if !viewModel.shouldHideSeparator {
VStack {
Spacer()
Divider().padding(.leading)
}
}
}
}
.frame(height: Layout.frameHeight)
.background(
backgroundView(assetPositionType: viewModel.corners)
)
}
Removing Spacer()
I have a image as thumbnail when image is tapped it should be expanded/zoom at the centre of screen with background as blur. I tried scale effect but the image is not on top of other view but looks like behind (see pics). How to achieve this zoomed imaged with blur background effect (see peacock pic this is the requirement)
#State var enlarge:Bool = false
var body: some View {
GeometryReader{geo in
VStack{
ZStack(alignment: .top){
LinearGradient(gradient:Gradient(colors: [.blue.opacity(0.3),.blue.opacity(0.2)]),startPoint: .top,endPoint:.bottom)
.ignoresSafeArea()
VStack(alignment: .leading,spacing :5){
HStack{
Text("Lorum Ipsum ackndweg")
.fontWeight(.semibold)
.padding(.top,15)
.padding(.leading,18)
.foregroundColor(ThemeColor.testName)
}
.frame(width: geo.size.width, alignment: .leading)
Image("capAm")
.resizable()
.scaledToFit()
.frame(width: 40, height: 40)
.padding(.leading,18)
.onTapGesture{
withAnimation
{
self.enlarge.toggle()
}
}
.scaleEffect(self.enlarge ? 4 : 1,anchor: .topLeading)
VStack(alignment:.leading,spacing: 5){
HStack{
Text("Turn Around Time :")
.font(.system(size: 14))
.foregroundColor(.red)
Text("Report Delivery : Daily")
.font(.system(size: 14))
.foregroundColor(.orange)
}
.frame(width: geo.size.width, alignment: .center)
VStack(alignment:.leading)
{
HStack{
Text("Turn Around Time(TAT) :")
.font(.system(size: 14))
.foregroundColor(.red)
Text("4 hours after acceptance of the sample at the centre")
.font(.system(size: 14))
.foregroundColor(.red)
.multilineTextAlignment(.leading)
}
}.frame(width: geo.size.width, alignment: .center)
}
}}}}}}
below just an idea
struct SwiftUIView: View {
#State private var enlarge = false
#State private var list = 1...10
#State private var current = 0
var body: some View {
ZStack {
ZStack {
Image(systemName: "\(current).circle")
.resizable()
.scaledToFit()
.frame(width: 60 , height: 60)
.padding()
.animation(.spring(), value: enlarge)
.foregroundColor(.yellow)
}
.frame(width: 300,
height: 200)
.background(Color.black.opacity(0.2))
.foregroundColor(Color.clear)
.cornerRadius(20)
.transition(.slide)
.opacity(self.enlarge ? 1 : 0)
.zIndex(2)
.onTapGesture{
withAnimation {
self.enlarge.toggle()
}
}
List {
ForEach(list, id:\.self) { i in
Label("detail of \(i)", systemImage: "\(i).circle")
.onTapGesture{
current = i
withAnimation {
self.enlarge.toggle()
}
}
}
}
.blur(radius: self.enlarge ? 3 : 0).offset(y: 1)
}
.onTapGesture{
withAnimation {
self.enlarge = false
}
}
}
}
How do I prevent word breaking for long words, e.g adjust font size to fit width?
Requirements:
The outer gray frame must have the same fixed size.
The should be 2 lines.
var body: some View {
VStack {
Spacer()
Image(systemName: "square")
.resizable()
.frame(width: 50, height: 50)
Spacer()
Text("Acknowledgement for the rest")
.allowsTightening(true)
.minimumScaleFactor(0.01)
.lineLimit(2)
.multilineTextAlignment(.center)
}
.padding()
.frame(width: 140, height: 150, alignment: .center)
.background(
ZStack {
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color(hex: "f9f9f9"))
}
)
}
use fixedSize modifier:
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Spacer()
Image(systemName: "square")
.resizable()
.frame(width: 50, height: 50)
Spacer()
Text("Acknowledgement for the rest")
.fixedSize() // <<: Here
.allowsTightening(true)
.minimumScaleFactor(0.01)
.lineLimit(nil)
.multilineTextAlignment(.center)
}
.padding()
.frame(height: 150)
.background(
ZStack {
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color.blue)
}
)
}
}
as you mention in the comment
The text coming in is dynamic. Is might be very long or very short. I
want to adjust the font size to fit.
it will adjust the font size to fit the width.
struct ContentView: View {
#State var acknowledgementString = "acknowledgement for the rest"
let mainWidth : CGFloat = 350//140
var body: some View {
Text(acknowledgementString)
.font(.system(size: 100))
.minimumScaleFactor(0.01)
.lineLimit(1)
.frame(width: mainWidth,height: mainWidth,alignment: .center )
.background(Color.red)
.onTapGesture {
acknowledgementString += " extra"
}
}
}