標籤:nslog 表徵圖 smis tar import 頂點 str mis text
一、
由於是模擬器縮得比較小,一些細線可能顯示不出來,不是bug哈。
二、用法
LFPopupMenuItem *item1 = [LFPopupMenuItem createWithTitle:@"小視頻" image:[UIImage imageNamed:@"icon_menu_record_normal"]]; LFPopupMenuItem *item2 = [LFPopupMenuItem createWithTitle:@"拍照" image:[UIImage imageNamed:@"icon_menu_shoot_normal"]]; LFPopupMenuItem *item3 = [LFPopupMenuItem createWithTitle:@"相簿" image:[UIImage imageNamed:@"icon_menu_album_normal"]];self.items = @[item1, item2, item3];LFPopupMenu *menu = [[LFPopupMenu alloc] init];[menu configWithItems:self.items action:^(NSInteger index) { NSLog(@"點擊了第%zi個",index); }]; [menu showArrowToView:sender];
更多方法見.h檔案,有詳細注釋
//// LFPopupMenu.h// LFPopupMenu//// Created by 張林峰 on 2017/8/20.// Copyright ? 2017年 張林峰. All rights reserved.//#import <UIKit/UIKit.h>typedef NS_ENUM(NSInteger, PopupMenuDirection) { PopupMenuDirection_Auto, //箭頭自動確定朝上還是下 PopupMenuDirection_Up, //箭頭朝上 PopupMenuDirection_Down //箭頭朝下};@interface LFPopupMenuItem : NSObject@property (nonatomic, strong) NSString *title;@property (nonatomic, strong) UIImage *image;/** 產生選項對象,標題和圖片至少要傳一個參數*/+ (LFPopupMenuItem *)createWithTitle:(NSString *)title image:(UIImage *)image;@end@interface LFPopupMenu : UIView/*******下面全是可選屬性,都有預設值**********/@property (nonatomic, strong) UIView *maskView;//半透明遮罩層,預設透明,可自行設定@property (nonatomic, strong) UIImage *imgBG;//背景圖,設定了這個就不用畫帶箭頭的框了。@property (nonatomic, strong) UIView *containerView;//容器,用於自訂彈窗內視圖@property (nonatomic, assign) CGFloat rowHeight;//行高,預設60@property (nonatomic, assign) CGFloat arrowH;//箭頭形高,預設9@property (nonatomic, assign) CGFloat arrowW;//箭頭形寬,預設9@property (nonatomic, assign) CGFloat minWidth;//彈窗最小寬度,預設0@property (nonatomic, assign) CGFloat popupMargin;//視窗距螢幕邊緣最小距離,預設5@property (nonatomic, assign) CGFloat leftEdgeMargin;//左邊距視窗的距離,預設16@property (nonatomic, assign) CGFloat rightEdgeMargin;//右邊距視窗的距離,預設16@property (nonatomic, assign) CGFloat textMargin;//文字距表徵圖的距離,預設8@property (nonatomic, assign) CGFloat lineMargin;//分割線左邊距,預設0@property (nonatomic, assign) CGFloat cornerRadius;//彈窗圓角,預設6@property (nonatomic, assign) CGFloat arrowCornerRadius;//箭頭的圓角,預設0@property (nonatomic, strong) UIColor *lineColor;//分割線顏色、邊框色,預設系統灰色@property (nonatomic, strong) UIFont *textFont;//預設15@property (nonatomic, strong) UIColor *textColor;//預設黑色@property (nonatomic, strong) UIColor *fillColor;//帶箭頭框的填充色,預設白色@property (nonatomic, assign) BOOL needBorder;//是否要邊框@property (nonatomic, assign) CGPoint anchorPoint;//設定背景圖的情況使用,背景圖的三角在背景圖的位置比例,如左上方(0,0),右下角(1,1),下邊中間(0.5,1)以此類推@property (nonatomic, strong) UIView *menuSuperView;//本菜單彈窗的父視圖,預設在Window上@property (nonatomic, assign) PopupMenuDirection direction;@property (nonatomic, copy) void(^dismissComplete)(void);//消失的回調/** 配置選項,注意:設定上面屬性之後調用 @param items 含文字和標題的對象數組 @param action 點擊回調,根據index判斷點擊的第幾個 */- (void)configWithItems:(NSArray<LFPopupMenuItem *>*)items action:(void(^)(NSInteger index))action;/**完全自訂菜單彈窗*/- (void)configWithCustomView:(UIView *)customView;/** 顯示菜單窗,有imgBG的情況下調用 @param point 本控制項“左上方”位置,相對window */- (void)showInPoint:(CGPoint)point;/** 顯示菜單窗,無imgBG的情況下調用 @param point 箭頭頂點位置,相對window */- (void)showArrowInPoint:(CGPoint)point;/** 顯示菜單窗,無imgBG的情況下調用(推薦) @param view 箭頭對準的view */- (void)showArrowToView:(UIView*)view;- (void)dismiss;@end
這隻是LFKit的一個子庫,LFKit地址https://github.com/zhanglinfeng/LFKit
只需LFPopupMenu的 pod ‘LFKit/LFPopupMenu‘
需要LFKit中所有自訂控制項的pod ‘LFKit/Component‘
需要總庫的 pod ‘LFKit‘
iOS 帶箭頭菜單選項彈窗LFPopupMenu