LTxMenu

[ Update v2.0.0 ] Similar to Facebook News Feed , Alipay Life , QZone and other social applications . click a drop-down button to display more functions

Introduction

​ In Facebook News Feed , Alipay Life , QZone and other social applications , they all contain a function drop-down button which would show a list of more functions when taped . I didn’t find any on GitHub , so I wrote a similar UI controls myself using Objective-C. :

GitHub link : LTxMenu

Get Start

  • Manually add the files into your Xcode project.
  • LTxMenu is available as LTxMenu in Cocoapods.

How To Use

​ Create a LTxMenuView Object:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
* class instance method with dataSource and delegate. you can also create with [[LTxMenuView alloc] init] then set the dataSource and the delegate.
**/
+ (instancetype)instanceWithDataSource:(id <LTxMenuViewDataSource>)dataSource delegate:(id <LTxMenuViewDelegate>)delegate;
/**
* show menuView in viewController from a special position.
* @param viewController the menuview 's container
* @param position the menuview 's arrow direction
**/
- (void)showMenu:(UIViewController*)viewController from:(CGRect)position;
/**
* hide the menuview. usually you did not need to call this method
**/
- (void)dismissMenu;

​ DataSource && Delegate

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma mark LTxMenuViewDelegate
@protocol LTxMenuViewDelegate<NSObject>
@optional
/**
* called when a specified index was selected.
**/
-(void)didSelectRowAtIndex:(NSInteger)index;
/**
* called when a specified accessoryView was selected.
**/
-(void)didSelectAccessoryView:(UIView*)accessoryView
atIndex:(NSInteger)index;
@end
#pragma mark LTxMenuViewDataSource
@protocol LTxMenuViewDataSource<NSObject>
@required
/**
* Returns the number of rows
**/
- (NSInteger)numberOfRows;
@optional
/**
* Returns the height of specified index. default value is 50.
**/
- (CGFloat)heightForRowAtIndex:(NSInteger)index;
/**
* Returns the attributedTitle of specified index.
**/
- (NSAttributedString*)attributedTitleForRowAtIndex:(NSInteger)index;
/**
* Returns the image of specified index.
**/
- (UIImage*)imageForRowAtIndex:(NSInteger)index;
/**
* Returns the accessoryViews placed at the end of specified index.
**/
- (NSArray<UIView*>*)accessoryViewsAtIndex:(NSInteger)index;
@end;

How it works

​ LTxMenu use LTxMenuItem class to config view showed in row. and LTxMenuView class with callback methods to calculate the UI performance . draw arrow and the border use UIBezierPath class . and the show/hide animation use UIKit.

Reference

https://github.com/kolyvan/kxmenu