Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.
Merged
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
4 changes: 0 additions & 4 deletions .slather.yml

This file was deleted.

8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
osx_image: xcode7.3
osx_image: xcode8
language: objective-c
cache: cocoapods
script: xcodebuild -workspace Demo.xcworkspace -scheme Tests -sdk iphonesimulator build test GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES clean test | xcpretty -c && exit ${PIPESTATUS[0]}
before_install:
- travis_wait 35; pod update
script:
- xcodebuild clean build -workspace Demo.xcworkspace -scheme "Tests" -sdk iphonesimulator | xcpretty
- xcodebuild test -project -workspace Demo.xcworkspace -scheme "Tests" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.0' | xcpretty
2 changes: 0 additions & 2 deletions Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@
14BD56211BEA57920043A673 /* HYPDemoLoginCollectionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HYPDemoLoginCollectionViewController.m; sourceTree = "<group>"; };
14BD56221BEA57920043A673 /* JSON.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = JSON.json; sourceTree = "<group>"; };
14BD56261BEA57FE0043A673 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
14C0AF7F1BD6D4230009ECBE /* .slather.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .slather.yml; sourceTree = "<group>"; };
14C0AF801BD6D4230009ECBE /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = "<group>"; };
14C0AF811BD6D4230009ECBE /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
14C0AF821BD6D4230009ECBE /* CONTRIBUTING.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -982,7 +981,6 @@
14C136501AB7849300B7B07A /* Metadata */ = {
isa = PBXGroup;
children = (
14C0AF7F1BD6D4230009ECBE /* .slather.yml */,
14C0AF801BD6D4230009ECBE /* .travis.yml */,
14C0AF811BD6D4230009ECBE /* CHANGELOG.md */,
14C0AF821BD6D4230009ECBE /* CONTRIBUTING.md */,
Expand Down
49 changes: 35 additions & 14 deletions Source/Cells/Popover/FORMDateFieldCell.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#import "FORMDateFieldCell.h"
#import "FORMFieldValue.h"

static const CGSize FORMDatePopoverSize = { 320.0f, 200.0f };
static const CGSize FORMDatePadPopoverSize = { 320.0f, 284.0f };
static const CGSize FORMDatePhonePopoverSize = { 320.0f, 200.0f };

@interface FORMDateFieldCell () <FORMTextFieldDelegate, FORMFieldValuesTableViewControllerDelegate>

Expand All @@ -14,8 +15,10 @@ @implementation FORMDateFieldCell
#pragma mark - Initializers

- (instancetype)initWithFrame:(CGRect)frame {
CGSize popoverSize = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? FORMDatePadPopoverSize : FORMDatePhonePopoverSize;

self = [super initWithFrame:frame contentViewController:self.fieldValuesController
andContentSize:FORMDatePopoverSize];
andContentSize:popoverSize];
if (!self) return nil;

self.fieldValuesController.delegate = self;
Expand All @@ -29,12 +32,15 @@ - (instancetype)initWithFrame:(CGRect)frame {
#pragma mark - Getters

- (CGRect)datePickerFrame {
CGFloat x = 0;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGRect bounds = [[UIScreen mainScreen] bounds];
x = (bounds.size.width - FORMDatePopoverSize.width) / 2.0;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return CGRectMake(0.0f, 25.0f, FORMDatePadPopoverSize.width, 196);
}
return CGRectMake(x, 25.0f, FORMDatePopoverSize.width, FORMDatePopoverSize.height);

CGFloat x = 0;
CGRect bounds = [[UIScreen mainScreen] bounds];
x = (bounds.size.width - FORMDatePhonePopoverSize.width) / 2.0;

return CGRectMake(x, 25.0f, FORMDatePhonePopoverSize.width, FORMDatePhonePopoverSize.height);
}

- (UIDatePicker *)datePicker {
Expand Down Expand Up @@ -80,18 +86,32 @@ - (void)dateChanged:(UIDatePicker *)datePicker {
- (void)updateWithField:(FORMField *)field {
[super updateWithField:field];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
FORMFieldValue *confirmValue = [FORMFieldValue new];
confirmValue.title = NSLocalizedString(@"Confirm", nil);
confirmValue.valueID = [NSDate date];
confirmValue.value = @YES;

FORMFieldValue *clearValue = [FORMFieldValue new];
clearValue.title = NSLocalizedString(@"Clear", nil);
clearValue.valueID = [NSDate date];
clearValue.value = @NO;

field.values = @[confirmValue, clearValue];
}

if (field.value) {
self.fieldValueLabel.text = [NSDateFormatter localizedStringFromDate:field.value
dateStyle:[self dateStyleForField:field]
timeStyle:[self timeStyleForField:field]];

self.fieldValueLabel.accessibilityValue = self.fieldValueLabel.text;
} else {
self.fieldValueLabel.text = nil;
}

self.iconImageView.image = [self fieldIcon];

if ([field.accessibilityLabel length] > 0) {
self.date.accessibilityLabel = field.accessibilityLabel;
} else {
Expand Down Expand Up @@ -139,13 +159,13 @@ - (UIImage *)fieldIcon {
case FORMFieldTypeDate:
case FORMFieldTypeDateTime:
return [UIImage imageNamed:@"calendar"
inBundle:bundle
compatibleWithTraitCollection:trait];
inBundle:bundle
compatibleWithTraitCollection:trait];
break;
case FORMFieldTypeTime:
return [UIImage imageNamed:@"clock"
inBundle:bundle
compatibleWithTraitCollection:trait];
compatibleWithTraitCollection:trait];
break;
default:
return nil;
Expand All @@ -157,8 +177,9 @@ - (UIImage *)fieldIcon {

- (void)updateContentViewController:(UIViewController *)contentViewController withField:(FORMField *)field {
self.fieldValuesController.field = self.field;

contentViewController.preferredContentSize = FORMDatePopoverSize;

CGSize popoverSize = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? FORMDatePadPopoverSize : FORMDatePhonePopoverSize;
contentViewController.preferredContentSize = popoverSize;

if (self.field.info) {
CGRect frame = self.datePicker.frame;
Expand Down
33 changes: 20 additions & 13 deletions Source/Cells/Popover/FORMFieldValuesTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,33 @@ @implementation FORMFieldValuesTableViewController
#pragma mark - Getters

- (FORMFieldValuesTableViewHeader *)headerView {
if (_headerView) return _headerView;
if (_headerView) return _headerView;

_headerView = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:FORMFieldValuesTableViewHeaderIdentifier];

return _headerView;
return _headerView;
}

#pragma mark - Setters

- (void)setField:(FORMField *)field {
_field = field;

UIBarButtonItem *clear = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Clear", nil) style:UIBarButtonItemStylePlain target:self action:@selector(clearButtonDidTap)];
BOOL shouldShowDoneButton = (_field.type == FORMFieldTypeDate || _field.type == FORMFieldTypeDateTime || _field.type == FORMFieldTypeTime);
if (shouldShowDoneButton) {
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonDidTap)];
self.navigationItem.rightBarButtonItems = @[done, clear];
} else {
self.navigationItem.rightBarButtonItem = clear;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
UIBarButtonItem *clear = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Clear", nil) style:UIBarButtonItemStylePlain target:self action:@selector(clearButtonDidTap)];
BOOL shouldShowDoneButton = (_field.type == FORMFieldTypeDate || _field.type == FORMFieldTypeDateTime || _field.type == FORMFieldTypeTime);
if (shouldShowDoneButton) {
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonDidTap)];
self.navigationItem.rightBarButtonItems = @[done, clear];
} else {
self.navigationItem.rightBarButtonItem = clear;
}

self.title = self.field.title;
}

self.values = [NSArray arrayWithArray:field.values];
self.headerView.field = field;
self.title = self.field.title;
[self.tableView reloadData];
}

Expand All @@ -53,8 +56,10 @@ - (void)viewDidLoad {
[self.tableView registerClass:[FORMFieldValueCell class] forCellReuseIdentifier:FORMFieldValueCellIdentifer];
[self.tableView registerClass:[FORMFieldValuesTableViewHeader class] forHeaderFooterViewReuseIdentifier:FORMFieldValuesTableViewHeaderIdentifier];

UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonDidTap)];
self.navigationItem.leftBarButtonItem = cancel;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonDidTap)];
self.navigationItem.leftBarButtonItem = cancel;
}
}

- (void)viewDidAppear:(BOOL)animated
Expand All @@ -69,7 +74,7 @@ - (void)viewDidAppear:(BOOL)animated
#pragma mark - Navigation Buttons Actions

- (void)cancelButtonDidTap {
[self dismissViewControllerAnimated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)doneButtonDidTap {
Expand Down Expand Up @@ -108,6 +113,8 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege
} else if (self.field.info) {
[self.headerView setField:self.field];
headerHeight = [self.headerView labelHeight];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
headerHeight = FORMFieldValuesCellHeight;
}

return headerHeight;
Expand Down
2 changes: 2 additions & 0 deletions Source/Cells/Popover/FORMFieldValuesTableViewHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ static NSString * const FORMFieldValuesTableViewHeaderIdentifier = @"FORMFieldVa

- (void)setInfoLabelFont:(UIFont *)infoLabelFont UI_APPEARANCE_SELECTOR;
- (void)setInfoLabelTextColor:(UIColor *)infoLabelTextColor UI_APPEARANCE_SELECTOR;
- (void)setTitleLabelFont:(UIFont *)titleLabelFont UI_APPEARANCE_SELECTOR;
- (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor UI_APPEARANCE_SELECTOR;

@end
68 changes: 63 additions & 5 deletions Source/Cells/Popover/FORMFieldValuesTableViewHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@interface FORMFieldValuesTableViewHeader ()

@property (nonatomic) UILabel *titleLabel;
@property (nonatomic) UILabel *infoLabel;

@end
Expand All @@ -16,21 +17,44 @@ - (instancetype)initWithReuseIdentifier:(NSString *)string {
self = [super initWithReuseIdentifier:string];
if (!self) return nil;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self addSubview:self.titleLabel];
}

[self addSubview:self.infoLabel];

return self;
}

#pragma mark - Getters
- (CGRect)titleLabelFrame {
return CGRectMake(0.0f, FORMInfoLabelY, FORMFieldValuesHeaderWidth, FORMLabelHeight);
}

- (UILabel *)titleLabel {
if (_titleLabel) return _titleLabel;

_titleLabel = [[UILabel alloc] initWithFrame:[self titleLabelFrame]];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
_titleLabel.numberOfLines = 0;
_titleLabel.text = self.field.title;

return _titleLabel;
}

- (CGRect)infoLabelFrame {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CGFloat y = CGRectGetMaxY(self.titleLabel.frame);
return CGRectMake(0.0f, y, FORMFieldValuesHeaderWidth, FORMLabelHeight * 1.1);
}

CGFloat x = 0;
CGFloat width = FORMFieldValuesHeaderWidth;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGRect bounds = [[UIScreen mainScreen] bounds];
width = bounds.size.width;
x = (width - FORMFieldValuesHeaderWidth) / 2.0;
}
CGRect bounds = [[UIScreen mainScreen] bounds];
width = bounds.size.width;
x = (width - FORMFieldValuesHeaderWidth) / 2.0;

return CGRectMake(x, FORMInfoLabelY, width, FORMLabelHeight * 1.1);
}

Expand All @@ -48,6 +72,12 @@ - (UILabel *)infoLabel {
- (CGFloat)labelHeight
{
CGFloat height = 0.0f;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
height += self.titleLabel.frame.origin.y * 2;
height += self.titleLabel.frame.size.height;
}

height += self.infoLabel.frame.size.height;

return height;
Expand All @@ -58,11 +88,27 @@ - (CGFloat)labelHeight
- (void)setField:(FORMField *)field {
_field = field;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.titleLabel.text = field.title;
}

self.infoLabel.text = field.info;

[self updateLabelFrames];
}

- (void)setTitleLabelFont:(UIFont *)titleLabelFont {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.titleLabel.font = titleLabelFont;
}
}

- (void)setTitleLabelTextColor:(UIColor *)titleLabelTextColor {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.titleLabel.textColor = titleLabelTextColor;
}
}

- (void)setInfoLabelFont:(UIFont *)infoLabelFont {
self.infoLabel.font = infoLabelFont;
}
Expand All @@ -74,11 +120,23 @@ - (void)setInfoLabelTextColor:(UIColor *)infoLabelTextColor {
#pragma marks - Private methods

- (void)updateLabelFrames {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self.titleLabel sizeToFit];
CGRect titleFrame = self.titleLabel.frame;
titleFrame.size.width = FORMFieldValuesHeaderWidth;
self.titleLabel.frame = titleFrame;
}

[self.infoLabel sizeToFit];
CGRect infoFrame = self.infoLabel.frame;
infoFrame.origin.y = [self infoLabelFrame].origin.y;
infoFrame.size.width = FORMFieldValuesHeaderWidth;
infoFrame.size.height = self.infoLabel.frame.size.height + 10.0;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
infoFrame.size.height = self.infoLabel.frame.size.height + 10.0;
}

self.infoLabel.frame = infoFrame;
}

Expand Down
12 changes: 12 additions & 0 deletions Source/Cells/Popover/FORMPopoverFieldCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ - (void)titleLabelPressed:(FORMFieldValueLabel *)titleLabel {

[self updateContentViewController:self.contentViewController withField:self.field];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.contentViewController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *presentationController = [self.contentViewController popoverPresentationController];
presentationController.sourceView = self;
presentationController.sourceRect = self.bounds;

UIViewController *topViewController = [UIViewController hyp_topViewController];
[topViewController presentViewController:self.contentViewController animated:YES completion:nil];
return;
}


UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.contentViewController];

navigationController.modalPresentationStyle = UIModalPresentationPopover;
Expand Down
2 changes: 1 addition & 1 deletion Source/Cells/Popover/FORMSelectFieldCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (void)updateWithField:(FORMField *)field {
} else {
self.fieldValueLabel.text = nil;
}

if ([field.accessibilityLabel length] > 0) {
self.fieldValueLabel.accessibilityLabel = field.accessibilityLabel;
} else {
Expand Down
Loading