react-native/ios/Native/Application/CustomButton/CustomButton.swift

60 lines
1.6 KiB
Swift

//
// CustomButton.swift
// RNPlayground
//
// Created by Artur Gurgul on 02/08/2025.
//
import UIKit
import SwiftUI
@objc(CustomButton)
class CustomButton: UIView {
private let label: UILabel = {
let lbl = UILabel()
lbl.text = "Hello from native"
lbl.textColor = .white
lbl.translatesAutoresizingMaskIntoConstraints = false
return lbl
}()
private let button: UIButton = {
let btn = UIButton(type: .system)
btn.setTitle("Click Me", for: .normal)
btn.setTitleColor(.white, for: .normal)
btn.translatesAutoresizingMaskIntoConstraints = false
return btn
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = .systemBlue
self.addSubview(label)
self.addSubview(button)
setupConstraints()
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupConstraints() {
NSLayoutConstraint.activate([
label.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 16),
label.centerYAnchor.constraint(equalTo: self.centerYAnchor),
button.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: 12),
button.centerYAnchor.constraint(equalTo: self.centerYAnchor),
button.trailingAnchor.constraint(lessThanOrEqualTo: self.trailingAnchor, constant: -16)
])
}
@objc private func buttonTapped() {
}
}