示例效果

示例效果.gif
在這里,我們簡單實現(xiàn)了一個全黑的氣泡彈框,每個選項包含了圖片、標題、內(nèi)容和下劃線,并且可以滾動視圖,選定某一項。
或者

示例

示例
使用示例
pod 'LPDPopoverViewObject'
只需兩步--不需要關注彈出的方向和箭頭的位置
1. 初始化一個LPDPopoverViewObject對象
LPDPopoverViewObject *popoverViewObject = [[LPDPopoverViewObject alloc] initWithCellName:@"LPDTableViewCell" cellHeight:50 viewWidth:150 sourceObject:nil];
參數(shù)解釋:
(1) cellName: popoverView中內(nèi)部tableView所需cell的類名,該cell可以包含xib,也可以使用純代碼,需符合LPDPopoverCellDelegate協(xié)議,即實現(xiàn)- (void)setViewModel:(id)viewModel;方法。注:該cell決定了popoverView的樣式,可以任意定制。如 示例中的LPDTableViewCell:
LPDTableViewCell.h
#import <UIKit/UIKit.h>
#import "LPDPopoverCellProtocol.h"
@interface LPDTableViewCell : UITableViewCell <LPDPopoverCellDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *logo;
@property (weak, nonatomic) IBOutlet UILabel *title;
@property (weak, nonatomic) IBOutlet UILabel *content;
@end
LPDTableViewCell.m
#import "LPDTableViewCell.h"
#import "LPDViewModel.h"
@implementation LPDTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
self.contentView.backgroundColor = [UIColor blackColor];
self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
self.selectedBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (void)setViewModel:(LPDViewModel *)model {
self.logo.image = [UIImage imageNamed:model.logo];
self.title.text = model.title;
self.content.text = model.content;
}
@end
注:LPDViewModel為一個簡單封裝了三個NSString屬性的類(例)。
LPDTableViewCell.xib

LPDTableViewCell.xib
(2)
cellHight: cell的高度。(3)
viewWidth: popoverView寬度。(4)
sourceObject: 決定了氣泡從哪一個視圖對象彈出,類型為UIView或UIBarButtonItem,在初始化時可以先不設置。
設置一些屬性
popoverViewObject.showTarget = self; //showTarget必須為一個控制器
popoverViewObject.didSeletedDelegate = self; //可以為任意對象,可實現(xiàn)選中某個cell時的委托方法
popoverViewObject.viewHeight = 150; //設置popoverView高度(默認為cell高度*cell數(shù)量,設置高度小于默認高度時可滾動)
2. Show!!
// 可以每次彈出時改變sourceObject
[self.popoverViewObject showWithDataArray:self.dataArray sourceObject:self.navigationItem.rightBarButtonItem];
//若初始化時設置過sourceObject,不用改變sourceObject
[self.popoverViewObject showWithDataArray:self.dataArray];
注:示例中self為一個控制器,popoverViewObject為其一個屬性。
參數(shù)解釋
dataArray: cell所需的數(shù)據(jù)源,在cell的委托方法里實現(xiàn)如何處理單個模型即可。