Posts

Showing posts with the label Swift

How to specify referrer URI when navigating to a page in Storyboards WebView in Swift

 When navigating a Storyboards WebView to a new URI, you may want to specify a  referrer URI . When using the WebView, we can do this using the load function. To use this function, we need to create a URLRequest. From a URLRequest, we can add a value for referrer to the request, then pass it into the load function of the WebView like so. Swift: let myURL = URL(string "https://codingguides.quinnscomputing.com" ) var myRequest = URLRequest(url: myURL!) myRequest.addValue( "https://www.quinnscomputing.com" , forHTTPHeaderField: "Referer" ) self . WebViewMain .load(myRequest) This will navigate the WebView to the specified URI with the specified referrer URI. This snippet is available in Codly. Click the appropriate link below to download the snippet. If you don't have Codly, it is available here in the Microsoft Store . Download

How to create a basic button in SwiftUI

  There are various ways to create a button in SwiftUI, let's start with a button that consists of text: Button("Print") { print("Button pressed") } Here, we specify the text for the button and inside the curly braces is the code we want to run when the button is press. In this case we print "Button pressed" but you can put any action you want there. The button will appear blue by default but you can change its colour with a modifier: Button("Print") { print("Button pressed") }.foregroundColor(.red) You may have noticed in iOS buttons don't have to be text, but they can consist of a range of different views to customise their look. For example you can give the button a background like this: Button(action: { print("Button pressed")}, label: { Text("Print") .foregroundColor(.white) .padding() .background(Color.blue) .cornerRadius(5) } Buttons don't require text either, they could be ...