Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
coderZsq committed Oct 12, 2019
1 parent 61444b6 commit 04e5346
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
41 changes: 25 additions & 16 deletions SQIntervalTimer/SQIntervalTimer/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,14 @@
<outlet property="delegate" destination="BYZ-38-t0r" id="IP9-Xy-nc1"/>
</connections>
</pickerView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hPF-DO-Rzk">
<rect key="frame" x="149.5" y="253" width="0.0" height="0.0"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="22"/>
<color key="textColor" red="0.76684117892066839" green="0.76684117892066839" blue="0.76684117892066839" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="13o-bN-7YL">
<rect key="frame" x="246.5" y="253" width="0.0" height="0.0"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="22"/>
<color key="textColor" red="0.76684117892066839" green="0.76684117892066839" blue="0.76684117892066839" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="计时" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kHu-8m-66E">
<rect key="frame" x="15" y="96" width="69" height="41"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="34"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<segmentedControl opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="yDf-Ly-a3k">
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="yDf-Ly-a3k">
<rect key="frame" x="301" y="101" width="98" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<segments>
<segment title=""/>
Expand All @@ -48,10 +41,16 @@
</segments>
<color key="selectedSegmentTintColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</segmentedControl>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="计时" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kHu-8m-66E">
<rect key="frame" x="15" y="96" width="69" height="41"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="34"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="hPF-DO-Rzk">
<rect key="frame" x="149.5" y="253" width="0.0" height="0.0"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="22"/>
<color key="textColor" red="0.76684117892066839" green="0.76684117892066839" blue="0.76684117892066839" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="13o-bN-7YL">
<rect key="frame" x="246.5" y="253" width="0.0" height="0.0"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="22"/>
<color key="textColor" red="0.76684117892066839" green="0.76684117892066839" blue="0.76684117892066839" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="执行" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="T9I-mf-wOK">
Expand Down Expand Up @@ -138,6 +137,13 @@
<action selector="operatorEventTouchUpInside:" destination="BYZ-38-t0r" eventType="touchUpInside" id="ZQ5-1H-g9x"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="60" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Qep-A9-VTe">
<rect key="frame" x="142" y="426" width="130" height="120"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="100"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
Expand All @@ -151,6 +157,7 @@
<constraint firstItem="Qjv-ld-sNL" firstAttribute="centerY" secondItem="PQY-cO-PkF" secondAttribute="centerY" id="C7L-Y2-fj1"/>
<constraint firstItem="13o-bN-7YL" firstAttribute="centerY" secondItem="8Xd-6t-B0t" secondAttribute="centerY" id="CuN-3w-unM"/>
<constraint firstItem="kli-UI-BPo" firstAttribute="leading" secondItem="5GG-lx-Gu6" secondAttribute="trailing" constant="33.5" id="D1h-q0-uD7"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="yDf-Ly-a3k" secondAttribute="trailing" constant="15" id="DnA-lw-3UE"/>
<constraint firstItem="5GG-lx-Gu6" firstAttribute="centerY" secondItem="8Xd-6t-B0t" secondAttribute="centerY" id="G19-l3-Si0"/>
<constraint firstItem="hPF-DO-Rzk" firstAttribute="leading" secondItem="T9I-mf-wOK" secondAttribute="trailing" constant="33.5" id="HXN-a6-dY0"/>
<constraint firstItem="Qjv-ld-sNL" firstAttribute="centerY" secondItem="YgB-3O-hDN" secondAttribute="centerY" id="JZX-Uz-BBH"/>
Expand All @@ -163,6 +170,7 @@
<constraint firstItem="6xl-uf-8Po" firstAttribute="centerX" secondItem="GWO-WE-4Fc" secondAttribute="centerX" id="QbR-Ld-nLV"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="6xl-uf-8Po" secondAttribute="trailing" constant="35" id="REI-Uw-I3y"/>
<constraint firstItem="5GG-lx-Gu6" firstAttribute="leading" secondItem="13o-bN-7YL" secondAttribute="trailing" constant="7.5" id="UER-90-AZI"/>
<constraint firstItem="yDf-Ly-a3k" firstAttribute="centerY" secondItem="kHu-8m-66E" secondAttribute="centerY" id="WSf-4K-GFQ"/>
<constraint firstItem="8Xd-6t-B0t" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" constant="7.5" id="jGe-kk-M1I"/>
<constraint firstItem="Qjv-ld-sNL" firstAttribute="centerX" secondItem="PQY-cO-PkF" secondAttribute="centerX" id="jSg-kn-13Y"/>
<constraint firstItem="kHu-8m-66E" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="15" id="qr7-lB-hzT"/>
Expand All @@ -173,6 +181,7 @@
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="countDownLabel" destination="Qep-A9-VTe" id="asv-iF-gSy"/>
<outlet property="pickView" destination="8Xd-6t-B0t" id="wK1-Iw-6Kg"/>
<outlet property="segmentedControl" destination="yDf-Ly-a3k" id="czB-NI-ewo"/>
<outletCollection property="circles" destination="GWO-WE-4Fc" id="fsu-1k-hEj"/>
Expand Down
29 changes: 25 additions & 4 deletions SQIntervalTimer/SQIntervalTimer/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ @interface ViewController ()<UIPickerViewDataSource, UIPickerViewDelegate>
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *labels;
@property (weak, nonatomic) IBOutlet UIPickerView *pickView;
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedControl;
@property (weak, nonatomic) IBOutlet UILabel *countDownLabel;
@property (strong, nonatomic) NSMutableArray *dataSource;
@property (strong, nonatomic) NSMutableArray *numbers;
@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
[self loadData];
[self initialData];
[self configureView];
}

- (void)loadData {
- (void)initialData {
self.dataSource = [NSMutableArray array];
NSMutableArray *actions = [NSMutableArray array];
for (NSUInteger i = 0; i <= 60; i++)
for (NSUInteger i = 1; i <= 60; i++)
[actions addObject:@(i).stringValue];
[self.dataSource addObject:actions];
NSMutableArray *breaks = [NSMutableArray array];
for (NSUInteger i = 1; i <= 60; i++)
for (NSUInteger i = 0; i <= 60; i++)
[breaks addObject:@(i).stringValue];
[self.dataSource addObject:breaks];
NSMutableArray *times = [NSMutableArray array];
Expand All @@ -43,6 +45,7 @@ - (void)loadData {
view.layer.cornerRadius = view.bounds.size.width * 0.5;
view.layer.masksToBounds = YES;
}
self.numbers = @[@0, @0, @0].mutableCopy;
}

- (void)configureView {
Expand All @@ -68,13 +71,31 @@ - (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleFor
return [[NSAttributedString alloc] initWithString:self.dataSource[component][row] attributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
self.numbers[component] = self.dataSource[component][row];
}

- (void)segmentedControlValueChanged:(UISegmentedControl *)sender {
for (UILabel *label in self.labels) {
label.text = @[@"", @"", @""][sender.selectedSegmentIndex];
}
}

- (IBAction)operatorEventTouchUpInside:(UIButton *)sender {
[self operatorsStyleToggle];

NSNumber *action = self.numbers[0];
__block NSUInteger number = action.integerValue;
[NSTimer scheduledTimerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
if (number == 0) {
[timer invalidate];
}
self.countDownLabel.text = @(number).stringValue;
number--;
}];
}

- (void)operatorsStyleToggle {
for (UIView *operator in self.operators) {
operator.backgroundColor = [UIColor colorWithRed:133 / 255. green:85 / 255. blue:32 / 255. alpha:1];
if ([operator isKindOfClass:UIButton.class]) {
Expand Down

0 comments on commit 04e5346

Please sign in to comment.