Create a button in Swift (Xcode) that will create a charge, create a charge using Stripe's API.
Creating your first charge using Xcode and Sublime with Stripe on a Swift iPhone 6
In iOS app development sometime we’ve to create Buttons
programmatically or dynamically.
Let’s create a new Single View iOS application in Xcode. Name the
project “MyDynamicButton”. Select swift as programming
language.
Now go to ViewController.swift. In ViewDidLoad method we’ll write
some codes that will add one button to the screen automatically at
run time.
Let’s create a new method createButton and write some codes inside
the method.
func createButton () {
let button = UIButton();
button.setTitle("Add", for: .normal)
button.setTitleColor(UIColor.blue, for: .normal)
button.frame = CGRect(x: 15, y: 50, width: 200, height: 100)
self.view.addSubview(button)
}
Explanation:
First we initialize a button object and keep it in button
variable
1 let button = UIButton();
Then we set title and color of title of it.
button.setTitle("Add", for: .normal)
button.setTitleColor(UIColor.blue, for: .normal)
In the following line of code, we add position and size of the button.
button.frame = CGRect(x: 15, y: 50, width: 200, height: 100)
Add the button to view.
self.view.addSubview(button)
Finally let’s call the createButton in viewDidLoad method.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a
nib.
createButton()
}
Now if you run the project (cmd + R) you can see a button
created. If you tap on the button, nothing will happen at this
moment. To call a method when button is pressed, we can
write:
button.addTarget(self, action: "buttonPressed:", for:
.touchUpInside)
Do not forget to add ‘:’ after action method name (i.e.
buttonPressed:). In action parameter of .addTarget, you set the
method name that should be called. Now write buttonPressed
method.
func buttonPressed(sender: UIButton!) {
let alertView = UIAlertView();
alertView.addButton(withTitle: "OK");
alertView.title = "Alert";
alertView.message = "Button Pressed!!!";
alertView.show();
}
The buttonPressed: method simply displays an alert view. Now run
the project and view result.
The whole ViewController.swift will look like this:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a
nib.
createButton()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func createButton () {
let button = UIButton();
button.setTitle("Add", for: .normal)
button.setTitleColor(UIColor.blue, for: .normal)
button.frame = CGRect(x: 15, y: 50, width: 200, height: 100)
self.view.addSubview(button)
}
func buttonPressed(sender: UIButton!) {
let alertView = UIAlertView();
alertView.addButton(withTitle: "OK");
alertView.title = "Alert";
alertView.message = "Button Pressed!!!";
alertView.show();
}
}
Create a button in Swift (Xcode) that will create a charge, create a charge using Stripe's...
Using Swift playground and / or the command line for macOS (open Xcode, create a new Xcode project, macOS, command line tool), practice the following exercises: Exercise: Swift Variables Declare 2 variables/constants with some random values and any name of your choice Considering these 2 variables, one as a value of PI and other as a radius of circle, find the area of circle Print the area of circle Declare a string variable explicitly with value “Northeastern”. Declare a string...
trying to make a cool calculator app with Xcode and swift . have all the tools newest version of Xcode a Mac, and programming experience in swift and other languages . need a fresh idea of a slick new calculator .
Write a Xcode app which when the button Introduction is clicked with a mouse prints the text "Hello! My name is"in the debugging area. Instead of "..." write your first name, space, your family name, and "dot". Warning Do not print the text "Hello! My name is.. " at the screen of the phone It will not be count even as a partial solution. Make YourFirstName YourFamilyName4.zip file and attach it to your e-mail. Write a Xcode app which when...
Using the template below create a GUI with a push button event. Use a JTextArea to display which button was selected. /******************* Name: Date: Notes: *******************/ import javax.swing.*; import java.awt.*; import java.awt.event.*; class Actions extends JFrame implements ActionListener { Create the components (textarea and buttons) public Actions() { create the window (include a close operation) create the container (include FlowLayout) add the event listeners (button.addActionListener) add the components } public...
Using Netbeans •Create a GUI consisting of two JTextFields and two JButtons. –When the first button is clicked, the contents of the first textfield is copied to the second textfield. –When the second button is clicked, both textfields are cleared. •Remember, the Javadocs are your friends.
Create ladder diagram after the immediate start of oil motor using push button. Spindle should start after 2 seconds. Also when spindle is stopped using a push button, oil motor should stop after 2 seconds of spindle stop. Note: No push button is needed to start the spindle.
Create the following in swift: Create a function that accepts a float for the wind speed and returns a string message based on its result. Use a Switch statement and ranges to handle all the cases, if something falls outside the list display the message “there is no such category” Wind Speed (in MPH) Result 74 to 95 - Category One 96 to 110 - Category Two 111 to 130 - Category Three 131 to 155 - Category Four 155...
Need solution in c++ that works on both Microsoft Visual 2017 and Xcode: Create a class Rectangle with attributes length and width, each of which defaults to 1. Provide methods that calculate the rectangle's perimeter and area. It has set and get methods for both length and width. The set methods should verify that length and width are each floating-point number larger than 0.0 and less than 20.0. Write a program to test class Rectangle
This assignemnt for Android development using Java Weather Forecaster App Goal: Create an app to display a weather forecast for the user’s current location Create the app titled Weather Forecaster The first screen will have a textbox for the user to enter a zip code and a button to submit When the user enters the zip code and clicks the button, the app will navigate to the weather forecast screen. The weather forecast screen will show the current weather for...