updated for Label

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-11-21 10:48:38 -06:00
parent 14e984942d
commit 088447bb65
5 changed files with 62 additions and 33 deletions

View File

@ -7,6 +7,7 @@
import Foundation
import UIKit
import VDS
class TextField: UITextField {
var textPadding = UIEdgeInsets(
@ -16,6 +17,15 @@ class TextField: UITextField {
right: 10
)
override init(frame: CGRect) {
super.init(frame: frame)
font = TypographicalStyle.BodyLarge.font
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func textRect(forBounds bounds: CGRect) -> CGRect {
layer.borderColor = UIColor.black.cgColor
layer.borderWidth = 1

View File

@ -36,7 +36,10 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
private weak var picker: UIPickerView?
fileprivate var selectedIndex = 0
private var subscribers = Set<AnyCancellable>()
private var label = UILabel()
private var label = Label().with {
$0.typograpicalStyle = .BodyLarge
}
private var button = Button().with { instance in
instance.size = .small
instance.use = .secondary
@ -88,11 +91,6 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
items.count + 1
}
public func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int ) -> String? {
guard row > 0, let item = items[row-1].rawValue as? String else { return "" }
return item
}
public func pickerView( _ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
guard row - 1 >= 0 else { return }
selectedIndex = row
@ -100,6 +98,21 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
text = "\(items[row-1].rawValue)"
pickerView.isHidden = true
}
public func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var label = UILabel()
if let v = view as? UILabel { label = v }
label.font = TypographicalStyle.TitleMedium.font
label.text = title(for: row)
label.textAlignment = .center
return label
}
private func title(for row: Int) -> String {
guard row > 0, let item = items[row-1].rawValue as? String else { return "" }
return item
}
}
public class SurfacePickerSelectorView: PickerSelectorView<Surface>{

View File

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="IOo-c1-iSM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="IOo-c1-iSM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@ -13,7 +14,7 @@
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="IOo-c1-iSM" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="PHn-rK-60b">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<rect key="frame" x="0.0" y="48" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
@ -33,25 +34,6 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="cell" textLabel="IUG-CW-6ON" style="IBUITableViewCellStyleDefault" id="1RT-mx-PaP">
<rect key="frame" x="0.0" y="44.5" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="1RT-mx-PaP" id="jMm-oH-21o">
<rect key="frame" x="0.0" y="0.0" width="385.5" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="IUG-CW-6ON">
<rect key="frame" x="20" y="0.0" width="357.5" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="0.0"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="COS-ke-xox" id="uRU-Qn-p3g"/>
<outlet property="delegate" destination="COS-ke-xox" id="Hfp-uJ-fdZ"/>

View File

@ -168,8 +168,9 @@ public class BaseViewController: UIViewController, Initable {
$0.spacing = 5
}
let label = UILabel().with {
let label = Label().with {
$0.text = label
$0.typograpicalStyle = .BodyLarge
}
formRow.addArrangedSubview(label)

View File

@ -7,6 +7,7 @@
import Foundation
import UIKit
import VDS
struct MenuComponent {
var title: String
@ -17,10 +18,32 @@ protocol Initable {
init()
}
class MenuCell: UITableViewCell {
var label = Label().with {
$0.typograpicalStyle = .BodyLarge
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setup(){
addSubview(label)
label.pinToSuperView(.init(top: 0, left: 16, bottom: 0, right: 0))
label.height(50)
}
}
class MenuViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
overrideUserInterfaceStyle = .light
tableView.register(MenuCell.self, forCellReuseIdentifier: "cell")
}
let items: [MenuComponent] = [
@ -48,13 +71,13 @@ class MenuViewController: UITableViewController {
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
guard items.count > indexPath.row,
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? MenuCell
else { return UITableViewCell() }
guard items.count > indexPath.row else { return UITableViewCell() }
let item = items[indexPath.row]
cell.textLabel?.text = item.title
cell.label.text = item.title
cell.accessoryType = .disclosureIndicator
return cell
}