Skip to content

Commit

Permalink
textView optimised and modify collectionview bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Oranges and lemons authored and Oranges and lemons committed Jan 30, 2018
1 parent 4886aec commit d7ea711
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 18 deletions.
4 changes: 2 additions & 2 deletions IBProperty.podspec
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "IBProperty"
s.version = "1.1.2"
s.version = "1.1.3"
s.ios.deployment_target = '7.0'
s.summary = "A iOS Kit which would adapt screen by XIB and Storyboard better, and use better for XIB and Storyboard。"
#s.description = <<-DESC
Expand All @@ -22,6 +22,6 @@ Pod::Spec.new do |s|
s.source_files = "IBProperty","IBProperty/**/*"
s.requires_arc = true
s.dependency "Aspects", "~> 1.4.1"
s.public_header_files = 'IBProperty/ORIBProperty.h'
# s.public_header_files = 'IBProperty/ORIBProperty.h'

end
7 changes: 5 additions & 2 deletions IBProperty/UICollectionViewFlowLayout+ORIBProperty.m
Expand Up @@ -48,6 +48,10 @@ - (void)setIb_numberItemsForRow:(NSInteger)ib_numberItemsForRow {
objc_setAssociatedObject(self, &ib_numberItemsForRowKey, @(ib_numberItemsForRow), OBJC_ASSOCIATION_COPY_NONATOMIC);
self.ib_adaptSize = YES;

[self.collectionView aspect_hookSelector:@selector(setBounds:) withOptions:AspectPositionAfter usingBlock:^{
self.ib_adaptSize = YES;
} error:nil];

}

- (NSInteger)ib_numberItemsForRow {
Expand All @@ -61,8 +65,7 @@ - (void)itemSizeAdapt {
self.itemSize = CGSizeMake(IB_HP(self.itemSize.width), IB_HP(self.itemSize.height));
}else {
CGFloat proportion = self.itemSize.width / self.itemSize.height ;

CGFloat width = (IB_HP(self.collectionView.bounds.size.width) - self.sectionInset.left - self.sectionInset.right -(self.ib_numberItemsForRow - 1) * self.minimumInteritemSpacing) / self.ib_numberItemsForRow - 1;
CGFloat width = (self.collectionView.bounds.size.width - self.sectionInset.left - self.sectionInset.right -(self.ib_numberItemsForRow - 1) * self.minimumInteritemSpacing) / self.ib_numberItemsForRow - 1;

self.itemSize = CGSizeMake(width, width / proportion);
}
Expand Down
11 changes: 10 additions & 1 deletion IBProperty/UITextView+ORIBProperty.m
Expand Up @@ -36,7 +36,7 @@ - (void)setIb_placeholder:(NSString *)ib_placeholder {
label.font = self.font;
label.textColor = [UIColor colorWithRed:213/255.f green:213/255.f blue:213/255.f alpha:1];
label.tag = placeholderTag;
label.frame = CGRectMake(self.textContainerInset.left + 5, self.textContainerInset.top, self.frame.size.width - (self.textContainerInset.left + self.textContainerInset.right), self.frame.size.height - (self.textContainerInset.top + self.textContainerInset.bottom));
[self frameChangedWith:label];
label.numberOfLines = 0;
[self addSubview:label];
}
Expand All @@ -50,6 +50,11 @@ - (void)setIb_placeholder:(NSString *)ib_placeholder {

__weak typeof (self) weakSelf = self;

[self aspect_hookSelector:@selector(setBounds:) withOptions:AspectPositionAfter usingBlock:^{
[weakSelf frameChangedWith:label];
[label sizeToFit];
} error:nil];

[self aspect_hookSelector:@selector(setText:) withOptions:AspectPositionAfter usingBlock:^{
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.ib_plceholderLabel.hidden = strongSelf.text.length > 0 || [strongSelf isFirstResponder];
Expand All @@ -72,6 +77,10 @@ - (void)setIb_placeholder:(NSString *)ib_placeholder {
}
}

- (void)frameChangedWith:(UILabel *)label {
label.frame = CGRectMake(self.textContainerInset.left + 5, self.textContainerInset.top, self.bounds.size.width - (self.textContainerInset.left + self.textContainerInset.right), self.bounds.size.height - (self.textContainerInset.top + self.textContainerInset.bottom));
}

- (NSString *)ib_placeholder {
return self.ib_plceholderLabel.text;
}
Expand Down
Binary file not shown.
23 changes: 12 additions & 11 deletions IBPropertyDemo/IBPropertyDemo/Base.lproj/Main.storyboard
Expand Up @@ -65,7 +65,7 @@
</userDefinedRuntimeAttributes>
</view>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="2.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="Lz7-DT-IRW">
<rect key="frame" x="20" y="115" width="335" height="178.5"/>
<rect key="frame" x="20" y="84" width="335" height="178.5"/>
<constraints>
<constraint firstAttribute="width" secondItem="Lz7-DT-IRW" secondAttribute="height" multiplier="15:8" id="2Ov-v0-gLK"/>
</constraints>
Expand Down Expand Up @@ -94,7 +94,7 @@
</userDefinedRuntimeAttributes>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="underline" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zze-cA-OUh">
<rect key="frame" x="20" y="323" width="71.5" height="21"/>
<rect key="frame" x="20" y="292" width="71.5" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
Expand All @@ -104,7 +104,7 @@
</userDefinedRuntimeAttributes>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="middleline" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="qDG-ZC-7ox">
<rect key="frame" x="20" y="352" width="78.5" height="21"/>
<rect key="frame" x="20" y="321" width="78.5" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
Expand All @@ -115,17 +115,17 @@
</userDefinedRuntimeAttributes>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dsi-hS-Z3a">
<rect key="frame" x="132.5" y="537" width="110" height="110"/>
<rect key="frame" x="137.5" y="547" width="100" height="100"/>
<color key="backgroundColor" red="0.4039215686" green="0.68235294120000001" blue="0.85098039219999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="width" constant="110" id="a0G-gL-u4i">
<constraint firstAttribute="width" constant="100" id="a0G-gL-u4i">
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="ib_adaptConstant" value="YES"/>
</userDefinedRuntimeAttributes>
</constraint>
<constraint firstAttribute="width" secondItem="dsi-hS-Z3a" secondAttribute="height" multiplier="1:1" id="l7V-lG-Hy4"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<state key="normal" title="限制重复点击">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
Expand All @@ -139,9 +139,9 @@
</connections>
</button>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="FTV-Ll-a3v">
<rect key="frame" x="20" y="385" width="343" height="144"/>
<rect key="frame" x="20" y="362" width="343" height="155"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="ib_placeholder" value="这是一个textView placeholder"/>
Expand All @@ -151,6 +151,7 @@
<userDefinedRuntimeAttribute type="number" keyPath="ib_borderWidth">
<real key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="boolean" keyPath="ib_adaptFont" value="YES"/>
</userDefinedRuntimeAttributes>
</textView>
</subviews>
Expand All @@ -161,12 +162,12 @@
<constraint firstItem="0Jf-Tj-dFf" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" id="ChM-NX-dfB"/>
<constraint firstItem="Lz7-DT-IRW" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="20" id="IaN-0b-rpP"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="FTV-Ll-a3v" secondAttribute="trailing" constant="12" id="TZU-7G-RMV"/>
<constraint firstItem="Lz7-DT-IRW" firstAttribute="top" secondItem="0Jf-Tj-dFf" secondAttribute="bottom" constant="51" id="Up1-D1-wo6"/>
<constraint firstItem="FTV-Ll-a3v" firstAttribute="top" secondItem="qDG-ZC-7ox" secondAttribute="bottom" constant="12" id="ZRa-UL-rTj"/>
<constraint firstItem="Lz7-DT-IRW" firstAttribute="top" secondItem="0Jf-Tj-dFf" secondAttribute="bottom" constant="20" id="Up1-D1-wo6"/>
<constraint firstItem="FTV-Ll-a3v" firstAttribute="top" secondItem="qDG-ZC-7ox" secondAttribute="bottom" constant="20" id="ZRa-UL-rTj"/>
<constraint firstItem="FTV-Ll-a3v" firstAttribute="leading" secondItem="qDG-ZC-7ox" secondAttribute="leading" id="Zaj-o8-LSL"/>
<constraint firstItem="qDG-ZC-7ox" firstAttribute="leading" secondItem="zze-cA-OUh" secondAttribute="leading" id="dgr-v5-5AP"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="dsi-hS-Z3a" secondAttribute="bottom" constant="20" id="eHK-MQ-2nN"/>
<constraint firstItem="dsi-hS-Z3a" firstAttribute="top" secondItem="FTV-Ll-a3v" secondAttribute="bottom" constant="8" id="ina-Z4-azc"/>
<constraint firstItem="dsi-hS-Z3a" firstAttribute="top" secondItem="FTV-Ll-a3v" secondAttribute="bottom" constant="30" id="ina-Z4-azc"/>
<constraint firstItem="zze-cA-OUh" firstAttribute="leading" secondItem="Lz7-DT-IRW" secondAttribute="leading" id="jr1-kM-2Za"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="0Jf-Tj-dFf" secondAttribute="trailing" id="l7w-2F-uxi"/>
<constraint firstItem="zze-cA-OUh" firstAttribute="top" secondItem="Lz7-DT-IRW" secondAttribute="bottom" constant="29.5" id="r6n-qK-TwD"/>
Expand Down
4 changes: 2 additions & 2 deletions IBPropertyDemo/IBPropertyDemo/IBCollectionViewController.m
Expand Up @@ -31,11 +31,11 @@ - (void)viewWillDisappear:(BOOL)animated {
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 5;
return 10;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return arc4random()%10 + 3;
return arc4random() % 11 + 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
Expand Down

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

0 comments on commit d7ea711

Please sign in to comment.