Convert to Button

Convert Button component to Android/iOS code.

Button Design to Swift/Kotlin Code

Buttons are the most used components in apps and they have app-specific actions. Buttons can have a title, background, or image as property/class. They may include more than one property. A button can have both properties at the same time. For example, background and title, or title and image, etc.

Buttons have 3 properties in Monday Hero:

Title: The text displayed over the button.

Background Image: The image used as the background of the button. Mostly it used when there is a text over the button.

Image: Icons are good examples of image buttons. They designed for having app-specific actions.

If a button has only a background color, Monday Hero can automatically understand the background color of the button. It will be defined as a View with the color.

In this case, Monday Hero automatically understands the blue rectangle as View and gets background color from the rectangle. So, defining the "Follow" label as the Title of the button will be enough. How to create a button and add a property/class can be seen in the GIF below.

When the button is created, the generated code will be like below.

Generated iOS/Android Code

The button code created is added to the page with the styles. Constraints are defined in the Storyboard file.

//ProfilePageViewController.swift
import UIKit

class ProfilePageViewController: UIViewController {
	
	// MARK: - Properties
  //Connection from an Interface Builder to a UI component
  
  // The button with an image and text
	@IBOutlet private weak var followButton: UIButton!
	@IBOutlet private weak var buttonImageView: UIImageView!
	
	//Button with an only image
	@IBOutlet private weak var profileButton: UIButton!

 	//Button with a text and background image
  @IBOutlet private weak var loginButton: UIButton!
  
	override func viewDidLoad() {
		super.viewDidLoad()
		setupViews()
		setupLayout()
	}
}

extension ProfilePageViewController {
	private func setupViews() {
		
		// The button with an image and text
		followButton.layer.cornerRadius = 6
		followButton.layer.masksToBounds =  true 
		followButton.backgroundColor = UIColor.cerulean
		followButton.setTitle(NSLocalizedString("follow", comment: ""),for: .normal)
		followButton.setTitleColor(UIColor.daisy, for: .normal)
		followButton.titleLabel?.font = UIFont.textStyle7
		followButton.contentHorizontalAlignment = .leading 
		followButton.contentEdgeInsets = UIEdgeInsets(top: 6, left: 9 , bottom: 6, right: 9)

		//Button with an only image
		profileButton.setImage(UIImage(named: "profileIcon") , for: .normal)
		
		//Button with a text and background image
		loginButton.setTitle(NSLocalizedString("login", comment: ""),for: .normal)
		loginButton.setTitleColor(UIColor.white, for: .normal)
		loginButton.titleLabel?.font = UIFont.textStyle2
		loginButton.contentHorizontalAlignment = .center 
		loginButton.setBackgroundImage(UIImage(named: "loginBackground") , for: .normal)
	}

	private func setupLayout() { 
		//Constraints are defined in Storyboard file.
	}
}

That's all for creating buttons on Monday Hero.

Last updated