Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Pod/Classes/PXDoubleNavTitle.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,22 @@
* changes the font for this title only. Setting this property to nil, falls back on the
* PXDoubleNavTitle class font.
*/
@property (nonatomic) UIFont* font UI_APPEARANCE_SELECTOR;
@property (nonatomic, nullable) UIFont* font UI_APPEARANCE_SELECTOR;

/**
* The title displayed in the navigation bar.
*/
@property (nonatomic, copy) NSString * title;
@property (nonatomic, copy, nullable) NSString * title;

/**
* A subtitle which, if set, is shown below the title in the navigation bar.
* If this property is nil or @@"", the position of the title text is placed where the default navigation title would be.
*/
@property (nonatomic, copy) NSString * subtitle;
@property (nonatomic, copy, nullable) NSString * subtitle;

/**
* Color applied to text of titles.
*/
@property (nonatomic) UIColor * tintColor UI_APPEARANCE_SELECTOR;
@property (nonatomic, nullable) UIColor * tintColor UI_APPEARANCE_SELECTOR;

@end
73 changes: 31 additions & 42 deletions Pod/Classes/PXDoubleNavTitle.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,27 @@ - (id)initWithFrame:(CGRect)frame
[_titleLabel setTextColor:[UIColor whiteColor]];
[_titleLabel setTextAlignment:NSTextAlignmentCenter];
[_titleLabel setFont:[[self font] fontWithSize:16.0f]];
// [_titleLabel setTranslatesAutoresizingMaskIntoConstraints:FALSE];
[_titleLabel setTranslatesAutoresizingMaskIntoConstraints:FALSE];
[self addSubview:_titleLabel];

_subtitleLabel = [UILabel new];
[_subtitleLabel setTextColor:[UIColor whiteColor]];
[_subtitleLabel setTextAlignment:NSTextAlignmentCenter];
[_subtitleLabel setFont:[[self font] fontWithSize:11.0f]];
// [_subtitleLabel setTranslatesAutoresizingMaskIntoConstraints:FALSE];
[_subtitleLabel setTranslatesAutoresizingMaskIntoConstraints:FALSE];
[self addSubview:_subtitleLabel];

#warning Uncomment when iOS 8+ adoption doesn't suck.
// NSDictionary* views = NSDictionaryOfVariableBindings(_titleLabel, _subtitleLabel);
// NSDictionary* metrics = @{};
//
// [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_titleLabel]|" options:0 metrics:metrics views:views]];
// [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_subtitleLabel]|" options:0 metrics:metrics views:views]];
// [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_titleLabel]" options:0 metrics:metrics views:views]];
// [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_subtitleLabel]|" options:0 metrics:metrics views:views]];
// [self addConstraint:[NSLayoutConstraint constraintWithItem:_subtitleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_titleLabel attribute:NSLayoutAttributeBaseline multiplier:1.0f constant:0.0f]];
NSDictionary* views = NSDictionaryOfVariableBindings(_titleLabel, _subtitleLabel);
NSDictionary* metrics = @{};

[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_titleLabel]|" options:0 metrics:metrics views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_subtitleLabel]|" options:0 metrics:metrics views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_titleLabel]" options:0 metrics:metrics views:views]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_subtitleLabel]|" options:0 metrics:metrics views:views]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:_subtitleLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_titleLabel attribute:NSLayoutAttributeBaseline multiplier:1.0f constant:0.0f]];

// call directly
// [self updateConstraints];
[self updateConstraints];
}
return self;
}
Expand All @@ -82,8 +81,8 @@ - (void)setSubtitle:(NSString *)subtitle

[self layoutIfNeeded];

//#warning trigger layout change
// [self setNeedsUpdateConstraints];
#warning trigger layout change
[self setNeedsUpdateConstraints];

[self sizeToFit];
}
Expand Down Expand Up @@ -136,33 +135,23 @@ - (CGSize)sizeThatFits:(CGSize)size
return CGSizeMake(width, height);
}

//- (void)updateConstraints
//{
// [self removeConstraints:_constraints];
// [_constraints removeAllObjects];
//
// NSDictionary* views = NSDictionaryOfVariableBindings(_titleLabel, _subtitleLabel);
// NSDictionary* metrics = @{};
// if (_haveSubtitle) {
// // show the label
// [_constraints addObject:[NSLayoutConstraint constraintWithItem:_subtitleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:_titleLabel attribute:NSLayoutAttributeHeight multiplier:0.6f constant:0.0f]];
// } else {
// [_constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_subtitleLabel(0)]" options:0 metrics:metrics views:views]];
// }
//
// [self addConstraints:_constraints];
//
// [super updateConstraints];
//}

//- (CGSize)sizeThatFitsThatDOESNTMAKEAPPLEFUCKITSELFWITHACACTUS:(CGSize)size // doesn't crash // apple has since fixed this
//{
// CGSize titleSize = [_titleLabel sizeThatFits:size];
// CGSize subtitleSize = [_subtitleLabel sizeThatFits:size];
// CGFloat width = MAX(titleSize.width, subtitleSize.width);
// CGFloat height = titleSize.height + (_haveSubtitle ? subtitleSize.height : 0.0f);
// NSLog(@"%f, %f", width, height);
// return CGSizeMake(width, height);
//}
- (void)updateConstraints
{
[self removeConstraints:_constraints];
[_constraints removeAllObjects];

NSDictionary* views = NSDictionaryOfVariableBindings(_titleLabel, _subtitleLabel);
NSDictionary* metrics = @{};
if (_haveSubtitle) {
// show the label
[_constraints addObject:[NSLayoutConstraint constraintWithItem:_subtitleLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:_titleLabel attribute:NSLayoutAttributeHeight multiplier:0.6f constant:0.0f]];
} else {
[_constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_subtitleLabel(0)]" options:0 metrics:metrics views:views]];
}

[self addConstraints:_constraints];

[super updateConstraints];
}

@end
8 changes: 4 additions & 4 deletions Pod/Classes/UIViewController+PXViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ typedef NS_ENUM(NSInteger, PXViewControllerNavBarStyle) {
/**
* The title displayed in the navigation bar.
*/
@property (nonatomic, copy) NSString * title;
@property (nonatomic, copy, nullable) NSString * title;

/**
* A subtitle which, if set, is shown below the title in the navigation bar.
* If this property is nil or @@"", the position of the title text is placed where the default navigation title would be.
*/
@property (nonatomic, copy) NSString * subtitle;
@property (nonatomic, copy, nullable) NSString * subtitle;

/**
* The color of the nav title and buttons (or the bar, depending on the style). Defaults to [UIColor whiteColor].
*/
@property (nonatomic, copy) UIColor * lightTintColor MZ_APPEARANCE_SELECTOR;
@property (nonatomic, copy, nullable) UIColor * lightTintColor MZ_APPEARANCE_SELECTOR;

/**
* The color of the nav bar (or the title and buttons, depending on the style). Defaults to [UIColor blackColor].
*/
@property (nonatomic, copy) UIColor * darkTintColor MZ_APPEARANCE_SELECTOR;
@property (nonatomic, copy, nullable) UIColor * darkTintColor MZ_APPEARANCE_SELECTOR;

/**
* Set to indicate whether or not this viewcontroller has the ability to go back. For example, modal viewcontrollers should not.
Expand Down