Ind.ie is now Small Technology Foundation.
Commit 9d5ae74e authored by Aral Balkan's avatar Aral Balkan

Dynamic type support & status text overflow; remove guides at runtime

parent 30a0c1e9
......@@ -172,6 +172,7 @@
);
inputPaths = (
"$(SRCROOT)/Carthage/Build/iOS/BonMot.framework",
"$(SRCROOT)/Carthage/Build/iOS/Delay.framework",
);
name = Carthage;
outputFileListPaths = (
......
......@@ -98,10 +98,10 @@
</mask>
</variation>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Q2i-Mp-9LN" userLabel="Text">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Q2i-Mp-9LN" userLabel="Status Text">
<rect key="frame" x="16" y="239.66666666666666" width="382" height="329.33333333333337"/>
<subviews>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" scrollEnabled="NO" editable="NO" usesAttributedText="YES" translatesAutoresizingMaskIntoConstraints="NO" id="PB8-0H-gLc">
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" usesAttributedText="YES" translatesAutoresizingMaskIntoConstraints="NO" id="PB8-0H-gLc">
<rect key="frame" x="0.0" y="0.0" width="382" height="329.33333333333331"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<attributedString key="attributedText">
......@@ -218,6 +218,13 @@
</variation>
</view>
<connections>
<outlet property="layoutElementStatusBadge" destination="1c7-hR-87O" id="l0S-99-fev"/>
<outlet property="layoutElementStatusText" destination="Q2i-Mp-9LN" id="oGX-Fl-a1u"/>
<outlet property="layoutGuideBase" destination="Da0-nj-Gxr" id="dC6-i4-NGQ"/>
<outlet property="layoutGuideBottomMargin" destination="97y-ZH-spg" id="pnO-n7-yRT"/>
<outlet property="layoutGuideStatusBadgeLeftMargin" destination="4IP-2x-4dT" id="Iru-7T-kOv"/>
<outlet property="layoutGuideStatusBadgeRightMargin" destination="P7i-RA-bJJ" id="V1N-i3-BdK"/>
<outlet property="layoutGuideTopMargin" destination="cUA-A3-7ag" id="tcC-MA-PXM"/>
<outlet property="statusImageView" destination="e5t-G8-1L2" id="gV2-J1-pzu"/>
<outlet property="statusTextView" destination="PB8-0H-gLc" id="eHF-sm-ZO0"/>
</connections>
......
......@@ -8,20 +8,40 @@
import UIKit
import BonMot
import Delay
class ViewController: UIViewController {
@IBOutlet weak var statusTextView: UITextView!
@IBOutlet weak var statusImageView: LDAlignmentImageView!
@IBOutlet weak var layoutGuideBase: UIView!
@IBOutlet weak var layoutGuideTopMargin: UIView!
@IBOutlet weak var layoutGuideStatusBadgeLeftMargin: UIView!
@IBOutlet weak var layoutGuideStatusBadgeRightMargin: UIView!
@IBOutlet weak var layoutGuideBottomMargin: UIView!
@IBOutlet weak var layoutElementStatusBadge: UIView!
@IBOutlet weak var layoutElementStatusText: UIView!
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.enableAdaptiveContentSizeMonitor()
// Hide the layout guides and reset the background colours on the layout elements.
let layoutGuides = [layoutGuideBase, layoutGuideTopMargin, layoutGuideStatusBadgeLeftMargin, layoutGuideStatusBadgeRightMargin, layoutGuideBottomMargin]
let layoutElements = [layoutElementStatusBadge, layoutElementStatusText]
for layoutGuide in layoutGuides { layoutGuide!.isHidden = true }
for layoutElement in layoutElements { layoutElement!.backgroundColor = UIColor.white }
// Set the image view to align the image internally from the left while also satisfying aspect fit.
statusImageView.imageContentMode = LDImageContentModeScaleAspectFit
statusImageView.imageHorizontalAlignment = LDImageHorizontalAlignmentLeft
updateText(true)
}
......@@ -32,27 +52,21 @@ class ViewController: UIViewController {
let linkFontSize:CGFloat = 16.0
let headingStyle = StringStyle(
.adapt(.body),
.font(.systemFont(ofSize: headlineFontSize, weight: .bold)),
.color(.black),
// .lineHeightMultiple(0.7),
.paragraphSpacingAfter(8.0)
// .adapt(.control)
)
let bodyStyle = StringStyle(
.adapt(.body),
.font(.systemFont(ofSize: bodyFontSize)),
// .lineHeightMultiple(1),
.color(.gray)
// .adapt(.body)
)
let linkStyle = StringStyle(
.font(.systemFont(ofSize: linkFontSize)),
.paragraphSpacingBefore(8.0),
// .lineHeightMultiple(1.25),
.color(.gray)
// .adapt(.body)
)
let linkStyle = bodyStyle.byAdding(.paragraphSpacingBefore(8.0))
var statusAttributedString:NSMutableAttributedString
......@@ -79,7 +93,8 @@ class ViewController: UIViewController {
// statusImage = self.blockerDisabledShieldImage
}
statusTextView.attributedText = statusAttributedString
statusTextView.attributedText = statusAttributedString.adapted(to: traitCollection)
_ = delay(0) { self.statusTextView.setContentOffset(.zero, animated: false) }
// The link’s text attributes have to be overwritten manually.
self.statusTextView.linkTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.darkGray, NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue, NSAttributedString.Key.underlineColor: UIColor.darkGray]
......@@ -91,6 +106,19 @@ class ViewController: UIViewController {
// MARK: - Notification handlers
//
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
// Scroll the status text to the top in the next stack frame in case the text overflows the visible
// area so that the top of the message is always visible. (This can happen when the text size is set
// to a large setting via Dynamic Type (Accessibility).
_ = delay(0) { self.statusTextView.setContentOffset(.zero, animated: false) }
}
override func willRotate(to toInterfaceOrientation: UIInterfaceOrientation, duration: TimeInterval)
{
// When the
}
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
guard
let launchSettingsURL = Foundation.URL(string: "better://launch-settings"),
......
github "Raizlabs/BonMot"
git "git@source.ind.ie:project/delay.git" "swift-4"
git "git@source.ind.ie:project/delay.git" "d1153f07ee69cf0b53cca2defb4835467a7d0b22"
github "Raizlabs/BonMot" "5.3"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment