iOS卡片容器iCards

项目中实现卡片式商家信息展示,通过左右滑动移除卡片,使用自定义view iCards,具备循环显示和非循环选择,提供多种控制属性及数据源代理方法,实现了类似iCarousel的效果。源码已开源。

项目中需要用卡片形式展示商家信息(当然这个展示风景和人物更好),希望左右滑动移除最上面的一张,卡片可以循环显示也可以不循环(即划走的再不见),GitHub上有类似项目,但都耦合在ViewController里,参考其实现封装了一个自定义view,取名iCards(因代理方法参考了第三方库iCarousel, 名称也学习了)。
iCards层叠显示卡片,每张卡片是任意view,你可以通过下边这个代理方法来定义:

- (UIView *)cards:(iCards *)cards viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view;

iCards目前有4个属性,分别控制是否需要循环显示卡片、相邻卡片相对位移、可见的卡片数量(假设你有100张,但可见的可以只有3张)以及是否允许滑动

/** default is YES*/
@property (nonatomic, assign) BOOL itemsShouldShowedCyclically;

/** We will creat this number of views, so not too many; default is 3 */
@property (nonatomic, assign) NSInteger numberOfVisibleItems;

/** offset for the next card to the current card, (it will decide the cards appearance, the top card is on top-left, top, or bottom-right and so on; default is (5, 5) */
@property (nonatomic, assign) CGSize offset;

/** If there is only one card, maybe you don't want to swipe it; */
@property (nonatomic, assign) BOOL swipEnabled;

有两个方法,见名知义,不多说:

- (void)reloadData;
- (UIView *)currentCard;

有两个数据源代理方法:

- (NSInteger)numberOfItemsInCards:(iCards *)cards;
- (UIView *)cards:(iCards *)cards viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view;

4个可选辅助代理方法:

- (void)cards:(iCards *)cards beginSwipingItemAtIndex:(NSInteger)index;
- (void)cards:(iCards *)cards didRemovedItemAtIndex:(NSInteger)index;
- (void)cards:(iCards *)cards didLeftRemovedItemAtIndex:(NSInteger)index;
- (void)cards:(iCards *)cards didRightRemovedItemAtIndex:(NSInteger)index;

以下是效果图:
iCards
iCards
iCards
iCards同样做了Pod支持。源码参见GitHub:iCards

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值