Latest 0.1.0
Homepage https://github.com/Assuner-Lee/LPDPopoverViewObject
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

LPDPopoverViewObject is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "LPDPopoverViewObject"

示例效果

示例效果.gif

在这里,我们简单实现了一个全黑的气泡弹框,每个选项包含了图片、标题、内容和下划线,并且可以滚动视图,选定某一项。

或者

示例
示例

使用示例

pod 'LPDPopoverViewObject'

只需两步–不需要关注弹出的方向和箭头的位置

1. 初始化一个LPDPopoverViewObject对象

LPDPopoverViewObject *popoverViewObject = [[LPDPopoverViewObject alloc] initWithCellName:@"LPDTableViewCell" cellHeight:50 viewWidth:150 sourceObject:nil];
参数解释:

(1) cellName: popoverView中内部tableView所需cell的类名,该cell可以包含xib,也可以使用纯代码,需符合LPDPopoverCellDelegate协议,即实现- (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;  //可以为任意对象,可实现选中某个cell时的委托方法
popoverViewObject.viewHeight = 150; //设置popoverView高度(默认为cell高度*cell数量,设置高度小于默认高度时可滚动)

2. Show!!

//  可以每次弹出时改变sourceObject
[self.popoverViewObject showWithDataArray:self.dataArray sourceObject:self.navigationItem.rightBarButtonItem];

//若初始化时设置过sourceObject,不用改变sourceObject
[self.popoverViewObject showWithDataArray:self.dataArray];

注:示例中self为一个控制器,popoverViewObject为其一个属性。

参数解释

dataArray: cell所需的数据源,在cell的委托方法里实现如何处理单个模型即可。

谢谢观看

水平有限,如有错误,请大家指出

Author

Assuner-Lee, [email protected]

License

LPDPopoverViewObject is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "LPDPopoverViewObject",
    "version": "0.1.0",
    "summary": "A short description of LPDPopoverViewObject.",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/Assuner-Lee/LPDPopoverViewObject",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Assuner-Lee": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Assuner-Lee/LPDPopoverViewObject.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "LPDPopoverViewObject/Classes/**/*"
}

Pin It on Pinterest

Share This