Skip to content

Commit db0ea66

Browse files
committed
add some customize option
1 parent 42c79c0 commit db0ea66

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

FEPopupMenuController/FEPopupMenuController.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,19 @@
5050
*/
5151
@property (nonatomic, assign) CGPoint contentViewPosition;
5252

53+
/**
54+
* the content view background color, default is white
55+
*/
56+
@property (nonatomic, strong) UIColor *contentViewBackgroundColor;
57+
58+
/**
59+
* the content view corner radius, default is 8.0
60+
*/
61+
@property (nonatomic, assign) CGFloat contentViewCornerRadius;
62+
63+
/**
64+
* title Color of each line, default is 0x565656
65+
*/
66+
@property (nonatomic, strong) UIColor *itemTitleColor;
67+
5368
@end

FEPopupMenuController/FEPopupMenuController.m

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ @interface FEPopupMenuController () <UITableViewDelegate,UITableViewDataSource,U
1616

1717
@property (nonatomic, strong) UIView *contentView;
1818
@property (nonatomic, strong) UITableView *tableView;
19-
2019
@property (nonatomic, strong) UITapGestureRecognizer *tapBackgroundGestureRecognizer;
20+
2121
@end
2222

2323
@implementation FEPopupMenuController
@@ -28,6 +28,8 @@ -(instancetype)initWithItems:(NSArray<FEPopupMenuItem *> *)items {
2828
self.automaticDismiss = YES;
2929
self.contentViewWidth = kDefaultContentViewWidth;
3030
self.contentViewPosition = CGPointMake(0,0);
31+
self.contentViewBackgroundColor = [UIColor whiteColor];
32+
self.contentViewCornerRadius = 8.0;
3133
}
3234
return self;
3335
}
@@ -45,8 +47,11 @@ - (void)viewDidLoad {
4547
[self.view addGestureRecognizer:self.tapBackgroundGestureRecognizer];
4648

4749
// init contentView
48-
self.contentView = [[UIView alloc] initWithFrame:CGRectMake(self.contentViewPosition.x, self.contentViewPosition.y, self.contentViewWidth, 44 * [self.items count])];
49-
self.contentView.layer.cornerRadius = 8.0;
50+
self.contentView = [[UIView alloc] initWithFrame:CGRectMake(self.contentViewPosition.x,
51+
self.contentViewPosition.y,
52+
self.contentViewWidth,
53+
44 * [self.items count])];
54+
self.contentView.layer.cornerRadius = self.contentViewCornerRadius;
5055
self.contentView.clipsToBounds = YES;
5156

5257
// init TableView
@@ -56,6 +61,7 @@ - (void)viewDidLoad {
5661
self.tableView.dataSource = self;
5762
self.tableView.separatorColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1];
5863
self.tableView.scrollEnabled = NO;
64+
self.tableView.backgroundColor = self.contentViewBackgroundColor;
5965

6066
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
6167
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
@@ -71,11 +77,6 @@ - (void)viewDidLoad {
7177
[self.tableView reloadData];
7278
}
7379

74-
- (void)didReceiveMemoryWarning {
75-
[super didReceiveMemoryWarning];
76-
// Dispose of any resources that can be recreated.
77-
}
78-
7980
#pragma mark show & dismiss
8081

8182
-(void)showInViewController:(UIViewController *)viewController atPosition:(CGPoint)position{
@@ -123,6 +124,12 @@ -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS
123124
FEPopupMenuItemCell *cell = [tableView dequeueReusableCellWithIdentifier:[FEPopupMenuItemCell identifier]];
124125
FEPopupMenuItem *item = self.items[indexPath.row];
125126
[cell configCellWithItem:item];
127+
128+
// config
129+
if (self.itemTitleColor) {
130+
cell.titleLabel.textColor = self.itemTitleColor;
131+
}
132+
126133
return cell;
127134
}
128135

FEPopupMenuController/FEPopupMenuItemCell.xib

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
<nil key="highlightedColor"/>
3131
</label>
3232
</subviews>
33+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
3334
<constraints>
3435
<constraint firstItem="Pr2-eR-Goo" firstAttribute="centerX" secondItem="H2p-sc-9uM" secondAttribute="centerX" constant="12.5" id="NcT-pd-2CY"/>
3536
<constraint firstItem="Pr2-eR-Goo" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="TWl-oN-K4f"/>
3637
<constraint firstItem="Pr2-eR-Goo" firstAttribute="leading" secondItem="HST-GA-K37" secondAttribute="trailing" constant="10" id="ffO-mn-u4v"/>
3738
<constraint firstItem="HST-GA-K37" firstAttribute="centerY" secondItem="H2p-sc-9uM" secondAttribute="centerY" id="vmu-q0-ccC"/>
3839
</constraints>
3940
</tableViewCellContentView>
41+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
4042
<connections>
4143
<outlet property="iconImageview" destination="HST-GA-K37" id="qGA-ej-xNz"/>
4244
<outlet property="titleLabel" destination="Pr2-eR-Goo" id="LXz-EP-SPp"/>

0 commit comments

Comments
 (0)