Prettify account cell

This commit is contained in:
Ivan Grachyov 2021-12-09 16:25:30 +03:00
parent 7abe8583c5
commit 6fbfcb308a
5 changed files with 92 additions and 13 deletions

View File

@ -0,0 +1,22 @@
// Copyright © 2021 Tokenary. All rights reserved.
import UIKit
class ButtonWithExtendedArea: UIButton {
var minimumHitArea = CGSize(width: 60, height: 60)
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if isHidden || !isUserInteractionEnabled || alpha < 0.01 { return nil }
// increase the hit frame to be at least as big as `minimumHitArea`
let buttonSize = bounds.size
let widthToAdd = max(minimumHitArea.width - buttonSize.width, 0)
let heightToAdd = max(minimumHitArea.height - buttonSize.height, 0)
let largerFrame = bounds.insetBy(dx: -widthToAdd / 2, dy: -heightToAdd / 2)
// perform hit test on larger frame
return (largerFrame.contains(point)) ? self : nil
}
}

View File

@ -3,15 +3,27 @@
import UIKit
import BlockiesSwift
protocol AccountTableViewCellDelegate: AnyObject {
func didTapMoreButton(accountCell: AccountTableViewCell)
}
class AccountTableViewCell: UITableViewCell {
private weak var cellDelegate: AccountTableViewCellDelegate?
@IBOutlet weak var avatarImageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
func setup(address: String) {
func setup(address: String, delegate: AccountTableViewCellDelegate) {
cellDelegate = delegate
avatarImageView.image = Blockies(seed: address.lowercased()).createImage()
let without0x = address.dropFirst(2)
titleLabel.text = without0x.prefix(4) + "..." + without0x.suffix(4)
}
@IBAction func moreButtonTapped(_ sender: Any) {
cellDelegate?.didTapMoreButton(accountCell: self)
}
}

View File

@ -9,40 +9,64 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="KGk-i7-Jjw" customClass="AccountTableViewCell" customModule="Tokenary_iOS" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="39" id="KGk-i7-Jjw" customClass="AccountTableViewCell" customModule="Tokenary_iOS" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="ooA-yA-X52">
<rect key="frame" x="12" y="5.5" width="33" height="33"/>
<rect key="frame" x="16" y="10" width="30" height="30"/>
<constraints>
<constraint firstAttribute="width" secondItem="ooA-yA-X52" secondAttribute="height" multiplier="1:1" id="O5G-AO-qmO"/>
<constraint firstAttribute="width" constant="33" id="Tw7-fi-eOY"/>
<constraint firstAttribute="width" constant="30" id="Tw7-fi-eOY"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
<integer key="value" value="15"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tiW-b9-8cH">
<rect key="frame" x="53" y="11.5" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<rect key="frame" x="58" y="12.5" width="51.5" height="25.5"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="21"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="BPJ-Sx-dhn" customClass="ButtonWithExtendedArea" customModule="Tokenary_iOS" customModuleProvider="target">
<rect key="frame" x="266" y="8" width="49" height="34"/>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" image="ellipsis.circle" catalog="system">
<preferredSymbolConfiguration key="preferredSymbolConfigurationForImage" configurationType="font">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
</preferredSymbolConfiguration>
</buttonConfiguration>
<connections>
<action selector="moreButtonTapped:" destination="KGk-i7-Jjw" eventType="touchUpInside" id="E3T-S9-nSB"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="ooA-yA-X52" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="3PX-D3-SeK"/>
<constraint firstItem="ooA-yA-X52" firstAttribute="top" secondItem="H2p-sc-9uM" secondAttribute="top" constant="10" id="02R-UC-mpp"/>
<constraint firstItem="tiW-b9-8cH" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="Qj2-8v-eMe"/>
<constraint firstItem="ooA-yA-X52" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="12" id="RLu-wN-tw5"/>
<constraint firstItem="tiW-b9-8cH" firstAttribute="leading" secondItem="ooA-yA-X52" secondAttribute="trailing" constant="8" id="XA9-9l-g2a"/>
<constraint firstItem="ooA-yA-X52" firstAttribute="leading" secondItem="H2p-sc-9uM" secondAttribute="leading" constant="16" id="RLu-wN-tw5"/>
<constraint firstAttribute="trailing" secondItem="BPJ-Sx-dhn" secondAttribute="trailing" constant="5" id="Wwi-0Q-tJo"/>
<constraint firstItem="tiW-b9-8cH" firstAttribute="leading" secondItem="ooA-yA-X52" secondAttribute="trailing" constant="12" id="XA9-9l-g2a"/>
<constraint firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="ooA-yA-X52" secondAttribute="bottom" constant="10" id="ZlY-bT-SPe"/>
<constraint firstItem="BPJ-Sx-dhn" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="qnE-3M-cZg"/>
</constraints>
</tableViewCellContentView>
<viewLayoutGuide key="safeArea" id="njF-e1-oar"/>
<inset key="separatorInset" minX="58" minY="0.0" maxX="0.0" maxY="0.0"/>
<connections>
<outlet property="avatarImageView" destination="ooA-yA-X52" id="KPM-ex-J4n"/>
<outlet property="titleLabel" destination="tiW-b9-8cH" id="I0g-8n-Shj"/>
</connections>
<point key="canvasLocation" x="137.68115942028987" y="122.54464285714285"/>
<point key="canvasLocation" x="137.68115942028987" y="124.55357142857142"/>
</tableViewCell>
</objects>
<resources>
<image name="ellipsis.circle" catalog="system" width="128" height="121"/>
</resources>
</document>

View File

@ -103,8 +103,17 @@ extension AccountsListViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellOfType(AccountTableViewCell.self, for: indexPath)
let wallet = wallets[indexPath.row]
cell.setup(address: wallet.ethereumAddress ?? "")
cell.setup(address: wallet.ethereumAddress ?? "", delegate: self)
return cell
}
}
extension AccountsListViewController: AccountTableViewCellDelegate {
func didTapMoreButton(accountCell: AccountTableViewCell) {
// TODO: implement
showMessageAlert(text: "Hello fren")
}
}

View File

@ -65,6 +65,7 @@
2C96D38F2762317300687301 /* AccountTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C96D38D2762317300687301 /* AccountTableViewCell.swift */; };
2C96D3902762317300687301 /* AccountTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C96D38E2762317300687301 /* AccountTableViewCell.xib */; };
2C96D392276232A300687301 /* UITableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C96D391276232A300687301 /* UITableView.swift */; };
2C96D3962762380400687301 /* ButtonWithExtendedArea.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C96D3952762380400687301 /* ButtonWithExtendedArea.swift */; };
2C9F0B6526BDC9AF008FA3D6 /* EthereumNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C9F0B6426BDC9AF008FA3D6 /* EthereumNetwork.swift */; };
2C9F0B6826BDCB2E008FA3D6 /* EthereumChain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C9F0B6726BDCB2E008FA3D6 /* EthereumChain.swift */; };
2CAA412526C7CD93009F3535 /* ReviewRequester.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CAA412426C7CD93009F3535 /* ReviewRequester.swift */; };
@ -239,6 +240,7 @@
2C96D38D2762317300687301 /* AccountTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTableViewCell.swift; sourceTree = "<group>"; };
2C96D38E2762317300687301 /* AccountTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccountTableViewCell.xib; sourceTree = "<group>"; };
2C96D391276232A300687301 /* UITableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITableView.swift; sourceTree = "<group>"; };
2C96D3952762380400687301 /* ButtonWithExtendedArea.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonWithExtendedArea.swift; sourceTree = "<group>"; };
2C9F0B6426BDC9AF008FA3D6 /* EthereumNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumNetwork.swift; sourceTree = "<group>"; };
2C9F0B6726BDCB2E008FA3D6 /* EthereumChain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumChain.swift; sourceTree = "<group>"; };
2CAA412426C7CD93009F3535 /* ReviewRequester.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewRequester.swift; sourceTree = "<group>"; };
@ -423,6 +425,7 @@
children = (
2C5FF97126C84F7B00B32ACC /* AppDelegate.swift */,
2C5FF97326C84F7B00B32ACC /* SceneDelegate.swift */,
2C96D394276237F600687301 /* Library */,
2CC6EF0E275E64840040CC62 /* Extensions */,
2CF255BB275A74A400AE54B9 /* Screens */,
2C5FF97726C84F7B00B32ACC /* Main.storyboard */,
@ -508,6 +511,14 @@
path = Accounts;
sourceTree = "<group>";
};
2C96D394276237F600687301 /* Library */ = {
isa = PBXGroup;
children = (
2C96D3952762380400687301 /* ButtonWithExtendedArea.swift */,
);
path = Library;
sourceTree = "<group>";
};
2CC6EF0E275E64840040CC62 /* Extensions */ = {
isa = PBXGroup;
children = (
@ -1054,6 +1065,7 @@
buildActionMask = 2147483647;
files = (
2CF255BA275A749300AE54B9 /* ApproveViewController.swift in Sources */,
2C96D3962762380400687301 /* ButtonWithExtendedArea.swift in Sources */,
2CF25599275A46E200AE54B9 /* PeerMeta.swift in Sources */,
2CF255A0275A47DD00AE54B9 /* Bundle.swift in Sources */,
2CF255AC275A48CF00AE54B9 /* EthereumNetwork.swift in Sources */,