Instantly share code, notes, and snippets.
Last active
February 22, 2019 13:57
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save DonMag/fb3c27146ab95dc4085560bfb88a898f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="AEZ-xs-jB5"> | |
<device id="retina4_7" orientation="portrait"> | |
<adaptation id="fullscreen"/> | |
</device> | |
<dependencies> | |
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/> | |
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | |
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | |
</dependencies> | |
<scenes> | |
<!--Buttons Test View Controller--> | |
<scene sceneID="7Ke-8l-ob9"> | |
<objects> | |
<viewController id="AEZ-xs-jB5" customClass="ButtonsTestViewController" customModule="XC10SWScratch" customModuleProvider="target" sceneMemberID="viewController"> | |
<view key="view" contentMode="scaleToFill" id="QSb-CR-gh2"> | |
<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" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="cSg-wk-RNQ"> | |
<rect key="frame" x="89.5" y="217.5" width="196" height="232"/> | |
<subviews> | |
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="0Ev-f7-hFH"> | |
<rect key="frame" x="0.0" y="0.0" width="196" height="40"/> | |
<subviews> | |
<button opaque="NO" tag="100" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="BGe-H3-nwf"> | |
<rect key="frame" x="0.0" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<constraints> | |
<constraint firstAttribute="height" constant="40" id="MRH-rT-Mfz"/> | |
<constraint firstAttribute="width" constant="40" id="UEX-rG-eQb"/> | |
</constraints> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="XC7-Mm-MAW"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="200" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Rk5-Jt-Jgk"> | |
<rect key="frame" x="52" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="h0W-lu-ufQ"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="300" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="u3E-t8-eRY"> | |
<rect key="frame" x="104" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="yvu-aJ-509"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="400" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ZDx-La-vXX"> | |
<rect key="frame" x="156" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="bpX-9X-2ga"/> | |
</connections> | |
</button> | |
</subviews> | |
</stackView> | |
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="noR-bP-WcE"> | |
<rect key="frame" x="0.0" y="48" width="196" height="40"/> | |
<subviews> | |
<button opaque="NO" tag="101" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JFl-gU-4w5"> | |
<rect key="frame" x="0.0" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<constraints> | |
<constraint firstAttribute="height" constant="40" id="AaR-Y1-CsB"/> | |
<constraint firstAttribute="width" constant="40" id="btA-cX-wVR"/> | |
</constraints> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="OKf-eL-bKH"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="201" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6Hz-5x-iz3"> | |
<rect key="frame" x="52" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="GTm-2y-ArH"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="301" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dJM-TI-gDB"> | |
<rect key="frame" x="104" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="rMx-O3-0Me"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="401" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="UUa-vr-BGo"> | |
<rect key="frame" x="156" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="7dg-7i-Ack"/> | |
</connections> | |
</button> | |
</subviews> | |
</stackView> | |
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="GVp-py-OxN"> | |
<rect key="frame" x="0.0" y="96" width="196" height="40"/> | |
<subviews> | |
<button opaque="NO" tag="102" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hjC-eL-rTa"> | |
<rect key="frame" x="0.0" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<constraints> | |
<constraint firstAttribute="height" constant="40" id="D4p-gO-d1V"/> | |
<constraint firstAttribute="width" constant="40" id="QEP-rc-pX2"/> | |
</constraints> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="bLc-4s-hzd"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="202" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Akt-LL-x48"> | |
<rect key="frame" x="52" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="zQC-2m-0gz"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="302" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="DvL-df-Q3b"> | |
<rect key="frame" x="104" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="0lV-qL-Cg9"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="402" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="TGx-x3-evQ"> | |
<rect key="frame" x="156" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="kok-YM-6km"/> | |
</connections> | |
</button> | |
</subviews> | |
</stackView> | |
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="dlA-AT-Fzt"> | |
<rect key="frame" x="0.0" y="144" width="196" height="40"/> | |
<subviews> | |
<button opaque="NO" tag="103" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="tDc-Lp-9nR"> | |
<rect key="frame" x="0.0" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<constraints> | |
<constraint firstAttribute="height" constant="40" id="SGM-hk-enK"/> | |
<constraint firstAttribute="width" constant="40" id="aBy-Eh-u6N"/> | |
</constraints> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="Pr3-45-Y0c"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="203" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="3ts-D7-FON"> | |
<rect key="frame" x="52" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="dQT-OC-uzs"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="303" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="PJy-zx-57V"> | |
<rect key="frame" x="104" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="qHg-gu-XFc"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="403" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="O60-RU-wM5"> | |
<rect key="frame" x="156" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="0nw-Bu-vM3"/> | |
</connections> | |
</button> | |
</subviews> | |
</stackView> | |
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" spacing="12" translatesAutoresizingMaskIntoConstraints="NO" id="2mt-6F-zMn"> | |
<rect key="frame" x="0.0" y="192" width="196" height="40"/> | |
<subviews> | |
<button opaque="NO" tag="104" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="yw4-Yk-dmk"> | |
<rect key="frame" x="0.0" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<constraints> | |
<constraint firstAttribute="height" constant="40" id="OXt-VW-49h"/> | |
<constraint firstAttribute="width" constant="40" id="f2Z-ya-Ab0"/> | |
</constraints> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="G4r-Mo-6Z2"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="204" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="SVS-gz-x19"> | |
<rect key="frame" x="52" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="Olu-Yi-xKp"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="304" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="T9p-EM-y7j"> | |
<rect key="frame" x="104" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="QSH-aM-owt"/> | |
</connections> | |
</button> | |
<button opaque="NO" tag="404" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Wll-eF-RTN"> | |
<rect key="frame" x="156" y="0.0" width="40" height="40"/> | |
<color key="backgroundColor" red="0.99953407049999998" green="0.98835557699999999" blue="0.47265523669999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> | |
<state key="normal" title="+"/> | |
<connections> | |
<action selector="valButtonTapped:" destination="AEZ-xs-jB5" eventType="touchUpInside" id="5yj-O4-erg"/> | |
</connections> | |
</button> | |
</subviews> | |
</stackView> | |
</subviews> | |
</stackView> | |
</subviews> | |
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | |
<constraints> | |
<constraint firstItem="cSg-wk-RNQ" firstAttribute="centerY" secondItem="QSb-CR-gh2" secondAttribute="centerY" id="2Y2-C7-WUB"/> | |
<constraint firstItem="cSg-wk-RNQ" firstAttribute="centerX" secondItem="QSb-CR-gh2" secondAttribute="centerX" id="dDY-is-TNt"/> | |
</constraints> | |
<viewLayoutGuide key="safeArea" id="A1n-S5-RdL"/> | |
</view> | |
</viewController> | |
<placeholder placeholderIdentifier="IBFirstResponder" id="azn-tD-2VK" userLabel="First Responder" sceneMemberID="firstResponder"/> | |
</objects> | |
<point key="canvasLocation" x="-1323.1884057971015" y="-64.402173913043484"/> | |
</scene> | |
</scenes> | |
</document> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ButtonsTestViewController: UIViewController { | |
// array to hold references to the "grid" buttons | |
var gridButtonsArray = [UIButton]() | |
var buttonVals: [[Int]] = [[Int]]() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// create 2-d array, 4 x 15 | |
for _ in 0...3 { | |
buttonVals.append(Array(repeating: 0, count: 15)) | |
} | |
// add a reference to every "grid" button to gridButtonsArray | |
for col in stride(from: 100, to: 400, by: 100) { | |
for row in 0..<15 { | |
if let b = view.viewWithTag(col + row) as? UIButton { | |
gridButtonsArray.append(b) | |
} | |
} | |
} | |
} | |
func resetButtonTitles() -> Void { | |
gridButtonsArray.forEach { b in | |
b.setTitle("+", for: .normal) | |
} | |
} | |
@IBAction func valButtonTapped(_ sender: Any) { | |
if let b = sender as? UIButton { | |
let t = b.tag | |
let col = t / 100 - 1 | |
let row = t % 100 | |
buttonVals[col][row] += 1 | |
b.setTitle("\(buttonVals[col][row])", for: .normal) | |
showSums() | |
} | |
} | |
func showSums() -> Void { | |
var col1sum = 0 | |
var col2sum = 0 | |
var col3sum = 0 | |
var col4sum = 0 | |
print() | |
// top 5 rows | |
col1sum = buttonVals[0][0...4].reduce(0, +) | |
col2sum = buttonVals[1][0...4].reduce(0, +) | |
col3sum = buttonVals[2][0...4].reduce(0, +) | |
col4sum = buttonVals[3][0...4].reduce(0, +) | |
print(col1sum, col2sum, col3sum, col4sum) | |
// middle 5 rows | |
col1sum = buttonVals[0][5...9].reduce(0, +) | |
col2sum = buttonVals[1][5...9].reduce(0, +) | |
col3sum = buttonVals[2][5...9].reduce(0, +) | |
col4sum = buttonVals[3][5...9].reduce(0, +) | |
print(col1sum, col2sum, col3sum, col4sum) | |
// bottom 5 rows | |
col1sum = buttonVals[0][10...14].reduce(0, +) | |
col2sum = buttonVals[1][10...14].reduce(0, +) | |
col3sum = buttonVals[2][10...14].reduce(0, +) | |
col4sum = buttonVals[3][10...14].reduce(0, +) | |
print(col1sum, col2sum, col3sum, col4sum) | |
print() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment