Skip to content

Commit 68bc9e1

Browse files
committed
Optimize cell layout
1 parent 833635c commit 68bc9e1

4 files changed

Lines changed: 14 additions & 39 deletions

File tree

FEPopupMenuController/FEPopupMenuItemCell.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@
1515
@property (weak, nonatomic) IBOutlet UIImageView *iconImageview;
1616
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
1717

18-
/**
19-
* if icon : priority high , else low
20-
*/
21-
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *icon2titleSpacingConstraint;
22-
23-
/**
24-
* if icon : priority low , else high
25-
*/
26-
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleXALignmentConstraint;
18+
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleXCenterConstraint;
2719

2820
/**
2921
* identifier for cell

FEPopupMenuController/FEPopupMenuItemCell.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
@implementation FEPopupMenuItemCell
1313

14-
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
15-
[super setSelected:selected animated:animated];
16-
17-
// Configure the view for the selected state
18-
}
19-
2014
+(NSString *)identifier{
2115
return @"FEPopupMenuItemCell";
2216
}
@@ -42,13 +36,11 @@ -(void)configCellWithItem:(FEPopupMenuItem *)item{
4236
self.iconImageview.image = item.iconImage;
4337
self.iconImageview.hidden = NO;
4438

45-
self.icon2titleSpacingConstraint.priority = 999.0;
46-
self.titleXALignmentConstraint.priority = UILayoutPriorityDefaultHigh;
39+
self.titleXCenterConstraint.constant = (15 + 10) / 2.0;
4740
}else{
4841
self.iconImageview.hidden = YES;
4942

50-
self.titleXALignmentConstraint.priority = 999.0;
51-
self.icon2titleSpacingConstraint.priority = UILayoutPriorityDefaultHigh;
43+
self.titleXCenterConstraint.constant = 0;
5244
}
5345
}
5446

FEPopupMenuController/FEPopupMenuItemCell.xib

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
33
<dependencies>
44
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
67
</dependencies>
78
<objects>
89
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -11,40 +12,35 @@
1112
<rect key="frame" x="0.0" y="0.0" width="163" height="44"/>
1213
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
1314
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
14-
<rect key="frame" x="0.0" y="0.0" width="163" height="43.5"/>
15+
<frame key="frameInset" width="163" height="43.5"/>
1516
<autoresizingMask key="autoresizingMask"/>
1617
<subviews>
1718
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="HST-GA-K37">
18-
<rect key="frame" x="54" y="14" width="15" height="15"/>
1919
<constraints>
2020
<constraint firstAttribute="width" constant="15" id="FB2-Bn-vWC"/>
2121
<constraint firstAttribute="height" constant="15" id="jMu-iQ-FmJ"/>
2222
</constraints>
2323
</imageView>
2424
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Pr2-eR-Goo">
25-
<rect key="frame" x="83" y="11" width="60" height="20.5"/>
2625
<constraints>
2726
<constraint firstAttribute="height" constant="20.5" id="j9P-gA-UQC"/>
28-
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="60" id="mfV-YN-MWX"/>
2927
</constraints>
3028
<fontDescription key="fontDescription" type="system" pointSize="15"/>
31-
<color key="textColor" red="0.33725490196078434" green="0.33725490196078434" blue="0.33725490196078434" alpha="1" colorSpace="calibratedRGB"/>
29+
<color key="textColor" red="0.33725490196078434" green="0.33725490196078434" blue="0.33725490196078434" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3230
<nil key="highlightedColor"/>
3331
</label>
3432
</subviews>
3533
<constraints>
36-
<constraint firstItem="HST-GA-K37" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="55v-Yx-HZi"/>
37-
<constraint firstItem="Pr2-eR-Goo" firstAttribute="centerX" secondItem="H2p-sc-9uM" secondAttribute="centerX" priority="999" id="NcT-pd-2CY"/>
34+
<constraint firstItem="Pr2-eR-Goo" firstAttribute="centerX" secondItem="H2p-sc-9uM" secondAttribute="centerX" constant="12.5" id="NcT-pd-2CY"/>
3835
<constraint firstItem="Pr2-eR-Goo" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="TWl-oN-K4f"/>
39-
<constraint firstItem="HST-GA-K37" firstAttribute="centerX" secondItem="H2p-sc-9uM" secondAttribute="centerX" constant="-20" id="XZY-4Q-Ca9"/>
40-
<constraint firstItem="Pr2-eR-Goo" firstAttribute="leading" secondItem="HST-GA-K37" secondAttribute="trailing" constant="14" id="muW-cY-F8V"/>
36+
<constraint firstItem="Pr2-eR-Goo" firstAttribute="leading" secondItem="HST-GA-K37" secondAttribute="trailing" constant="10" id="ffO-mn-u4v"/>
37+
<constraint firstItem="HST-GA-K37" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="vmu-q0-ccC"/>
4138
</constraints>
4239
</tableViewCellContentView>
4340
<connections>
44-
<outlet property="icon2titleSpacingConstraint" destination="muW-cY-F8V" id="pXn-U0-aak"/>
4541
<outlet property="iconImageview" destination="HST-GA-K37" id="qGA-ej-xNz"/>
4642
<outlet property="titleLabel" destination="Pr2-eR-Goo" id="LXz-EP-SPp"/>
47-
<outlet property="titleXALignmentConstraint" destination="NcT-pd-2CY" id="h8S-1o-haH"/>
43+
<outlet property="titleXCenterConstraint" destination="NcT-pd-2CY" id="MdD-Ou-hCc"/>
4844
</connections>
4945
<point key="canvasLocation" x="25.5" y="409"/>
5046
</tableViewCell>

FEPopupMenuControllerDemo/FEPopupMenuControllerDemo/ViewController.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ - (void)viewDidLoad {
2626
FEPopupMenuItem *item2 = [[FEPopupMenuItem alloc] initWithTitle:@"男生" iconImage:[UIImage imageNamed:@"homenear_icon_boy"] action:^{
2727
NSLog(@"selected item2...");
2828
}];
29-
FEPopupMenuItem *item3 = [[FEPopupMenuItem alloc] initWithTitle:@"女生" iconImage:[UIImage imageNamed:@"homenear_icon_girl"] action:^{
29+
FEPopupMenuItem *item3 = [[FEPopupMenuItem alloc] initWithTitle:@"女生女生" iconImage:[UIImage imageNamed:@"homenear_icon_girl"] action:^{
3030
NSLog(@"selected item3...");
3131
}];
3232
FEPopupMenuItem *item4 = [[FEPopupMenuItem alloc] initWithTitle:@"高级筛选" iconImage:nil action:^{
@@ -40,11 +40,6 @@ -(void)viewDidLayoutSubviews{
4040
[self.popupMenuController moveContentViewToPosition:[self calculateMenuShowPoint]];
4141
}
4242

43-
- (void)didReceiveMemoryWarning {
44-
[super didReceiveMemoryWarning];
45-
// Dispose of any resources that can be recreated.
46-
}
47-
4843
/**
4944
* right top bar button action
5045
*/

0 commit comments

Comments
 (0)