Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #28 from inloop/feature/uinavigationbar_large_titl…
Browse files Browse the repository at this point in the history
…e_text_style

FEAT: UINavigationBar - largeTitleTextStyle
  • Loading branch information
jakubpetrik authored Feb 19, 2018
2 parents 55effe5 + eb8a18f commit 7714f4d
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- Styles (0.7.4)
- Styles (0.8.4)

DEPENDENCIES:
- Styles (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: ../

SPEC CHECKSUMS:
Styles: e3fbab59f12faaac84c03a2942f8098a333e2270
Styles: 653c3a901bddf8b5416b610e95b638b165d86837

PODFILE CHECKSUM: d955debdf2315159e98d47d1c3d294214ae453cf

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/Styles.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Example/Pods/Target Support Files/Styles/Info.plist

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Example/Styles/Resources/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<rect key="frame" x="139.5" y="195" width="96" height="30"/>
<state key="normal" title="~~ Default ~~"/>
<state key="highlighted" title="Highlighted"/>
<connections>
<action selector="handleButtonAction:" destination="BYZ-38-t0r" eventType="touchUpInside" id="EsY-LT-jCG"/>
</connections>
</button>
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Here, type you can." minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="onp-1l-LkD">
<rect key="frame" x="122.5" y="268" width="130" height="20"/>
Expand Down
9 changes: 8 additions & 1 deletion Example/Styles/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ let magentaFootnote = TextStyle(
.foregroundColor(.magenta)
)

let largeTitle = TextStyle(
.font(.preferredFont(forTextStyle: .largeTitle)),
.foregroundColor(.white),
.backgroundColor(.magenta)
)

let blueFootnote = magentaFootnote.updating(.foregroundColor(.blue))

@UIApplicationMain
Expand All @@ -148,7 +154,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
UITextField.appearance().setViewStyle(blue, for: .inactive)
UITextField.appearance().setPlaceholderStyle(greenHeadline, for: .inactive)
UITextField.appearance().setPlaceholderStyle(magentaFootnote, for: .editing)
UINavigationBar.appearance().textStyle = h1
UINavigationBar.appearance().titleTextStyle = body
UINavigationBar.appearance().largeTitleTextStyle = largeTitle
UINavigationBar.appearance().tintColor = .yellow
UINavigationBar.appearance().barTintColor = .black
UINavigationBar.appearance().barStyle = .black
Expand Down
10 changes: 10 additions & 0 deletions Example/Styles/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import UIKit

class ExLabel: UILabel { }

extension Bool {
mutating func toggle() {
self = !self
}
}

class ViewController: UIViewController {
@IBOutlet var label: ExLabel!
@IBOutlet var button: UIButton!
Expand All @@ -19,5 +25,9 @@ class ViewController: UIViewController {
@IBAction func handleTap(_ sender: UITapGestureRecognizer) {
textField.resignFirstResponder()
}

@IBAction func handleButtonAction(_ sender: UIButton) {
navigationController?.navigationBar.prefersLargeTitles.toggle()
}
}

2 changes: 1 addition & 1 deletion Styles.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Styles'
s.version = '0.7.4'
s.version = '0.8.4'
s.summary = 'UI Elements rapid styling'
s.description = <<-DESC
UIElements styling made easy, declarative and rapid.
Expand Down
5 changes: 3 additions & 2 deletions Styles/Classes/UIElement+Extensions/UINavigationBar+Styles.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@class TextStyle;

@interface UINavigationBar (Styles)
@property (nonatomic, copy) TextStyle *textStyle UI_APPEARANCE_SELECTOR;
@interface UINavigationBar (TextStyle)
@property (nonatomic, copy) TextStyle *titleTextStyle UI_APPEARANCE_SELECTOR;
@property (nonatomic, copy) TextStyle *largeTitleTextStyle UI_APPEARANCE_SELECTOR API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
@end
8 changes: 6 additions & 2 deletions Styles/Classes/UIElement+Extensions/UINavigationBar+Styles.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

@implementation UINavigationBar (Styles)

SYNTHESIZE_PROPERTY_OBJ(TextStyle, textStyle, TextStyle);
SYNTHESIZE_PROPERTY_OBJ(TextStyle, titleTextStyle, TitleTextStyle);
SYNTHESIZE_PROPERTY_OBJ(TextStyle, largeTitleTextStyle, LargeTitleTextStyle);

- (void)applyStyle {
[super applyStyle];
self.titleTextAttributes = [self.textStyle attributes];
self.titleTextAttributes = [self.titleTextStyle attributes];
if (@available(iOS 11.0, *)) {
self.largeTitleTextAttributes = [self.largeTitleTextStyle attributes];
}
}

@end

0 comments on commit 7714f4d

Please sign in to comment.