Here's a sample implementation of containerBackground. LMEntryView is your widget view.
struct LMWidget: Widget {
var supportedFamilies: [WidgetFamily] {
[.systemSmall,
.systemMedium]
}
var body: some WidgetConfiguration {
StaticConfiguration(kind: "LMWidget",
provider: LMTimelineProvider()) { entry in
if #available(iOS 17, *) {
LMEntryView(entry: entry)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.containerBackground(Color("WidgetBackground"), for: .widget)
} else {
LMEntryView(entry: entry)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color("WidgetBackground"))
}
}
.configurationDisplayName("L_M_Widget_Title".localized)
.description("L_M_Widget_Description".localized)
.supportedFamilies(supportedFamilies)
.contentMarginsDisabled()
}
}
Post
Replies
Boosts
Views
Activity
Doesn't look like 6s is compatible with iOS 16.
Check this support article
Bye Bye
You might want to consider implementing a Navigation Bar Appearance ViewModifier and applying it to your VStack
struct MainView: View {
var body: some View {
ScrollView {
Text("Text")
}
.frame(maxWidth: .infinity)
}
}
struct TabBarView: View {
var body: some View {
Color.pink
.frame(maxWidth: .infinity)
.frame(height: 55)
}
}
struct ContentView: View {
var body: some View {
NavigationView {
VStack(spacing: 0) {
MainView()
TabBarView() // Commenting this out fixes the problem.
}
.background(.red) // Commenting this out _also_ fixes the problem.
.opaqueNavigationBar(
foregroundColor: .white,
backgroundColor: .systemBrown,
tintColor: .systemIndigo,
shadowColor: .darkGray)
.navigationBarTitleDisplayMode(.inline)
.navigationTitle("Main View")
}
}
}
public struct OpaqueNavigationBarAppearance: ViewModifier {
public init(
font: UIFont = .preferredFont(forTextStyle: .headline),
largeTitleFont: UIFont = .preferredFont(forTextStyle: .largeTitle),
foregroundColor: UIColor = .clear,
backgroundColor: UIColor = .secondarySystemBackground,
tintColor: UIColor = .clear,
shadowColor: UIColor = .clear) {
let appearance = UINavigationBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.titleTextAttributes = [.foregroundColor: foregroundColor, .font: font]
appearance.largeTitleTextAttributes = [.foregroundColor: foregroundColor, .font: largeTitleFont]
appearance.shadowColor = shadowColor
appearance.backgroundColor = backgroundColor
UINavigationBar.appearance().standardAppearance = appearance
UINavigationBar.appearance().scrollEdgeAppearance = appearance
UINavigationBar.appearance().compactAppearance = appearance
UINavigationBar.appearance().tintColor = tintColor
}
public func body(content: Content) -> some View {
return content
}
}
public extension View {
func opaqueNavigationBar(
font: UIFont = .preferredFont(forTextStyle: .headline),
largeTitleFont: UIFont = .preferredFont(forTextStyle: .largeTitle),
foregroundColor: UIColor = .clear,
backgroundColor: UIColor = .secondarySystemBackground,
tintColor: UIColor = .clear,
shadowColor: UIColor = .clear) -> some View {
ModifiedContent(
content: self,
modifier: OpaqueNavigationBarAppearance(
font: font,
largeTitleFont: largeTitleFont,
foregroundColor: foregroundColor,
backgroundColor: backgroundColor,
tintColor: tintColor,
shadowColor: shadowColor))
}
}
import SwiftUI
struct S1: View {
@State var aa = 0
var body: some View {
TabView{
S2(aa: $aa)
.tabItem {
Image(systemName: "person.fill")
Text("1")
}
.toolbarBackground(.visible, for: .tabBar)
.toolbarBackground(.ultraThickMaterial, for: .tabBar)
S3(aa: $aa)
.tabItem {
Image(systemName: "person.fill")
Text("2")
}
.toolbarBackground(.visible, for: .tabBar)
.toolbarBackground(.ultraThickMaterial, for: .tabBar)
}
}
}
struct S1_Previews: PreviewProvider {
static var previews: some View {
S1()
}
}
import SwiftUI
struct S2: View {
@State var bb = 0
@Binding var aa: Int
var body: some View {
VStack{
HStack{
Button {
aa += 1
if aa > bb {
bb += 1
}
} label: {
Text("+")
.frame(width: 140, height: 50)
.background {
RoundedRectangle(cornerRadius: 15, style: .continuous)
.fill(Color(red: 0.888, green: 0.536, blue: 0.785))
.frame(width: 140, height: 50)
}
.foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69))
.multilineTextAlignment(.center)
.bold()
.dynamicTypeSize(.accessibility1)
}
Button {
aa -= 1
if aa < bb {
bb -= 1
}
} label: {
Text("-")
.frame(width: 140, height: 50)
.background {
RoundedRectangle(cornerRadius: 15, style: .continuous)
.fill(Color(red: 0.888, green: 0.536, blue: 0.785))
.frame(width: 140, height: 50)
}
.foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69))
.multilineTextAlignment(.center)
.bold()
.dynamicTypeSize(.accessibility1)
}
}
Text(String(bb))
.frame(width: 140, height: 50)
.background {
RoundedRectangle(cornerRadius: 15, style: .continuous)
.fill(Color(red: 0.888, green: 0.536, blue: 0.785))
.frame(width: 140, height: 50)
}
.foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69))
.multilineTextAlignment(.center)
.bold()
.dynamicTypeSize(.accessibility3)
}
.onChange(of: aa) { newValue in
if aa > bb {
bb += 1
} else if aa < bb {
bb -= 1
}
}
}
}
struct S2_Previews: PreviewProvider {
static var previews: some View {
S2(aa: .constant(0))
}
}
import SwiftUI
struct S3: View {
@Binding var aa: Int
var body: some View {
HStack{
Button {
aa += 1
} label: {
Text("+")
.frame(width: 140, height: 50)
.background {
RoundedRectangle(cornerRadius: 15, style: .continuous)
.fill(Color(red: 0.888, green: 0.536, blue: 0.785))
.frame(width: 140, height: 50)
}
.foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69))
.multilineTextAlignment(.center)
.bold()
.dynamicTypeSize(.accessibility1)
}
Button {
aa -= 1
} label: {
Text("-")
.frame(width: 140, height: 50)
.background {
RoundedRectangle(cornerRadius: 15, style: .continuous)
.fill(Color(red: 0.888, green: 0.536, blue: 0.785))
.frame(width: 140, height: 50)
}
.foregroundColor(Color(red: 1.002, green: 0.967, blue: 0.69))
.multilineTextAlignment(.center)
.bold()
.dynamicTypeSize(.accessibility1)
}
}
}
}
struct S3_Previews: PreviewProvider {
static var previews: some View {
S3(aa: .constant(0))
}
}
You should make aa a State var aa = 0 in S1 and make it a @Binding var aa: Int in both S2 & S3.
If you want to keep the itemSize same across devices you should consider calculating the interitemspacing based on the collection view content width.
If you want to keep the interitemspacing same then calculate the itemSize based on the collection view content width.
This is assuming you always want the same number of items on each row.
Alternately consider using Compositional Layout which provides more flexibility in configuring collection view layouts.
Compositional Layout
For https://earthquake.phivolcs.dost.gov.ph header is
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
For https://earthquake.phivolcs.dost.gov.ph/2022_Earthquake_Information/September/2022_0922_1059_B2.html header is
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
Look at the charset
Have you tried using UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self])
Here is a screenshot
Did you put the breakpoint on line 42? The code execution is stopping on line 42 because you or someone has set a breakpoint on that line. Just tap on the blue breakpoint indicator on line 42 and it should disable it or you can right click the indicator and delete the breakpoint.
You can set accentColor on the NavigationStack
All the code you want to execute after refreshResources should be inside the Task block.
class ViewController: UIViewController {
@IBOutlet weak var navigationBar: UINavigationBar!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
navigationBar.delegate = self
}
}
extension ViewController: UINavigationBarDelegate {
func position(for bar: UIBarPositioning) -> UIBarPosition {
return .topAttached
}
}