lkzhao / uicomponent Goto Github PK
View Code? Open in Web Editor NEWA modern, declarative approach to building user interfaces with UIKit.
License: MIT License
A modern, declarative approach to building user interfaces with UIKit.
License: MIT License
Is this component compatible with IOS 11
Hi, it's me again😅
I used the SimpleViewComponent
component in the example, I cannot get the correct size
What can I do to make the component width and height correct?
this my code
SimpleViewComponent<UIButton>().update {
$0.setTitle("button", for: .normal)
$0.setTitleColor(.systemBlue, for: .normal)
}.backgroundColor(.brown)
Size:zero
Thanks for your help
Hi,
I want rounded corners, but I don’t know the specific height of this Text component. Is there any way to set it?
It is possible to increase a similar SwiftUI.clipShape(Capsule())
modified it? Because rounded corners are often used
this my code
Text("Round Style").textColor(.white).inset(h: 20, v: 10).background(SimpleViewComponent<UIView>().backgroundColor(.black))
How to hide an existing view element
Consider compatibility with macOS?
Hope have a sample to implement drag and drop.
I switched the language to ar and adjusted the card demo, and found that the rtl layout is not supported. Is there any plan to support it?
// CardViewController.swift
private class CardView: UIView {
let titleLabel: UILabel = {
let label = UILabel()
label.font = UIFont.boldSystemFont(ofSize: 22)
label.backgroundColor = .red
return label
}()
let subtitleLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 16)
label.backgroundColor = .green
return label
}()
let leadingLabel: UILabel = {
let label = UILabel()
label.text = "Leading"
label.font = UIFont.systemFont(ofSize: 16)
label.backgroundColor = .gray
return label
}()
let trailingLabel: UILabel = {
let label = UILabel()
label.text = "Trailing"
label.font = UIFont.systemFont(ofSize: 16)
label.backgroundColor = .orange
return label
}()
var onTap: (() -> Void)?
var data: CardData? {
didSet {
titleLabel.text = data?.title
subtitleLabel.text = data?.subtitle
}
}
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .blue
layer.cornerRadius = 8
layer.shadowColor = UIColor.black.cgColor
layer.shadowRadius = 4
layer.shadowOpacity = 0.2
layer.shadowOffset = CGSize(width: 0, height: 2)
addSubview(titleLabel)
addSubview(subtitleLabel)
addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didTap)))
addSubview(leadingLabel)
addSubview(trailingLabel)
leadingLabel.translatesAutoresizingMaskIntoConstraints = false
trailingLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
leadingLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20),
leadingLabel.topAnchor.constraint(equalTo: subtitleLabel.bottomAnchor, constant: 8),
trailingLabel.leadingAnchor.constraint(equalTo: leadingLabel.trailingAnchor, constant: 8),
trailingLabel.topAnchor.constraint(equalTo: subtitleLabel.bottomAnchor, constant: 8),
])
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc func didTap() {
onTap?()
}
override func layoutSubviews() {
super.layoutSubviews()
titleLabel.frame = CGRect(x: 20, y: 12, width: bounds.width - 40, height: 30)
subtitleLabel.frame = CGRect(x: 20, y: 40, width: bounds.width - 40, height: 30)
}
}
private struct CardComponent: Component {
let data: CardData
let onTap: () -> Void
func layout(_ constraint: Constraint) -> CardRenderNode {
CardRenderNode(data: data, onTap: onTap, size: CGSize(width: constraint.maxSize.width, height: 80 + 30))
}
}
// CardViewController3.swift
private struct Card: ComponentBuilder {
let card: CardData
let onTap: () -> Void
func build() -> some Component {
VStack(spacing: 8) {
Text(card.title).font(UIFont.boldSystemFont(ofSize: 22))
.size(width: .fill)
.backgroundColor(.red)
Text(card.subtitle)
.backgroundColor(.green)
HStack(spacing: 8) {
Text("Leading")
.backgroundColor(.gray)
Text("Trailing")
.backgroundColor(.orange)
}
}
.inset(top: 16, left: 20, bottom: 16, right: 50).size(width: .fill).tappableView(onTap).id(card.id)
.backgroundColor(.blue)
.with(\.layer.shadowColor, UIColor.black.cgColor)
.with(\.layer.shadowRadius, 4)
.with(\.layer.shadowOffset, CGSize(width: 0, height: 2))
.with(\.layer.shadowOpacity, 0.2)
.with(\.layer.cornerRadius, 8)
}
}
My own project also uses this library, after importing your library all I use this will report ambiguity error
If the concept of state binding is added to the data, I think this can be better
This is a great binding design, I think it will help you
reference: State
Hi,
I use HStack Layout Component has a long string, I hope it will wrap, but it goes beyond the screen.
Is it possible to add CSS Flex Wrap
properties to the Stack component?
e.g
HStack(wrap: .wrap || .noWrap) {
......
}
this my codes
HStack code
HStack {
Text("long long long long long long long long long long long long long long long long long long long long long long long long long long long long text")
}.size(width: .percentage(1)).inset(h: 10, v: 10)
VStack code
VStack {
Text("long long long long long long long long long long long long long long long long long long long long long long long long long long long long text")
}.size(width: .percentage(1)).inset(h: 10, v: 10)
Also exceed the screen boundary
VStack {
HStack {
VStack {
Text("long long long long long long long long long long long long long long long long long long long long long long long long long long long long text")
}
}
}.size(width: .percentage(1)).inset(h: 10, v: 10)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.