Convert to Button
Convert Button component to Android/iOS code.
Button Design to Swift/Kotlin Code


Generated iOS/Android Code
Last updated
Convert Button component to Android/iOS code.


Last updated
//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.
}
}
<!--activityUserProfile.xml-->
<!--The button with a background color and text-->
<Button
android:id="@+id/followButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/follow"
android:textAllCaps="false"
android:background="@drawable/followbutton_background_drawable"
style="@style/textStyle11"
android:textAlignment="textStart"
android:textColor="?attr/daisy"
android:paddingLeft="9dp"
android:paddingRight="9dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:layout_marginEnd="56dp"
android:layout_marginTop="42dp"
android:layout_marginBottom="37dp"
app:layout_constraintStart_toEndOf="@+id/profilPictureImageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nolanAlexTextView"
app:layout_constraintBottom_toTopOf="@+id/alexanderNolanTextView"/>
<!--Button with an only image-->
<Button
android:id="@+id/profileButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
android:background="@android:color/transparent"
android:drawableBottom="@drawable/profileicon"
android:layout_marginEnd="23dp"
android:layout_marginBottom="13dp"
app:layout_constraintStart_toEndOf="@+id/buttonImageView"
app:layout_constraintEnd_toEndOf="@+id/baseView"
app:layout_constraintTop_toBottomOf="@+id/userPicturesBID"
app:layout_constraintBottom_toBottomOf="@+id/baseView"/>
<!--Button with a text and background image -->
<Button
android:id="@+id/loginButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/login"
android:textAllCaps="false"
android:background="@android:color/transparent"
style="@style/textStyle15"
android:textAlignment="center"
android:textColor="?attr/white"
android:layout_marginStart="108dp"
android:layout_marginEnd="86dp"
android:layout_marginBottom="18dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rectangleView"
app:layout_constraintBottom_toBottomOf="parent"/><!--Drawables/followbutton_background_drawable.xml-->
<!--The button with a background color and text-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="?attr/cerulean"/>
<corners android:radius="6dp"/>
</shape>
</item>
</selector>