提交 4823baec 编写于 作者: J John Hampton

Adds button and click event placeholder

上级 1f78e59c
......@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
37154FE2222CBCFE006731A8 /* RatingControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37154FE1222CBCFE006731A8 /* RatingControl.swift */; };
3775361422234238005EE5FE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3775361322234238005EE5FE /* AppDelegate.swift */; };
3775361622234238005EE5FE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3775361522234238005EE5FE /* ViewController.swift */; };
3775361922234238005EE5FE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3775361722234238005EE5FE /* Main.storyboard */; };
......@@ -34,6 +35,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
37154FE1222CBCFE006731A8 /* RatingControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RatingControl.swift; sourceTree = "<group>"; };
3775361022234238005EE5FE /* iOSTemplate.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOSTemplate.app; sourceTree = BUILT_PRODUCTS_DIR; };
3775361322234238005EE5FE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
3775361522234238005EE5FE /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
......@@ -100,6 +102,7 @@
3775361322234238005EE5FE /* AppDelegate.swift */,
3775361522234238005EE5FE /* ViewController.swift */,
3775361722234238005EE5FE /* Main.storyboard */,
37154FE1222CBCFE006731A8 /* RatingControl.swift */,
3775361A22234238005EE5FE /* Assets.xcassets */,
3775361C22234238005EE5FE /* LaunchScreen.storyboard */,
3775361F22234238005EE5FE /* Info.plist */,
......@@ -256,6 +259,7 @@
buildActionMask = 2147483647;
files = (
3775361622234238005EE5FE /* ViewController.swift in Sources */,
37154FE2222CBCFE006731A8 /* RatingControl.swift in Sources */,
3775361422234238005EE5FE /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
......
......@@ -18,8 +18,8 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="top" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="l36-fK-dfQ">
<rect key="frame" x="0.0" y="40" width="375" height="424.5"/>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" axis="vertical" alignment="top" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="l36-fK-dfQ">
<rect key="frame" x="0.0" y="40" width="375" height="542.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Meal Name" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="n9u-9b-TSl">
<rect key="frame" x="0.0" y="0.0" width="86.5" height="20.5"/>
......@@ -50,6 +50,9 @@
<outletCollection property="gestureRecognizers" destination="UAM-fK-D64" appends="YES" id="uEG-WL-m3E"/>
</connections>
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5FE-RR-A0X" customClass="RatingControl" customModule="iOSTemplate" customModuleProvider="target">
<rect key="frame" x="0.0" y="432.5" width="200" height="110"/>
</stackView>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="DYv-F4-28V" secondAttribute="trailing" id="TIM-g5-3jW"/>
......
//
// RatingControl.swift
// iOSTemplate
//
// Created by John Hampton on 3/3/19.
//
import UIKit
class RatingControl: UIStackView {
// MARK: Initialization
override init(frame: CGRect) {
super.init(frame: frame)
setupButtons()
}
required init(coder: NSCoder) {
super.init(coder: coder)
setupButtons()
}
// MARK: Button Action
@objc func ratingButtonTapped(button: UIButton) {
print("Button pressed 👍")
}
// MARK: Private Methods
private func setupButtons() {
// Create the button
let button = UIButton()
button.backgroundColor = UIColor.red
// Add constraints
button.translatesAutoresizingMaskIntoConstraints = false
button.heightAnchor.constraint(equalToConstant: 44.0).isActive = true
button.widthAnchor.constraint(equalToConstant: 44.0).isActive = true
// Setup the button action
button.addTarget(self, action: #selector(RatingControl.ratingButtonTapped(button:)), for: .touchUpInside)
// Add the button to the stack
addArrangedSubview(button)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册