很简单的一个东西,不过为了应付各种情况,比如cell上有问号,点击弹出来,比如这样
又或者需要这样:
这时候需要做一个统一管理的样式,外部负责传入样式,view内部根据样式来定制。比如横竖,比如是否需要竖直列表的方式等。
上代码:
.h文件:
typedef enum: NSUInteger{
AskViewShowTypeVertical = 0,// 水平展示
AskViewShowTypeHoritical = 1// 竖直展示
}AskViewShowType;
typedef enum: NSUInteger{
// 箭头所依附的方向
ArrowDependDerectionTop = 0,
ArrowDependDerectionLeft = 1,
ArrowDependDerectionBottom = 2,
ArrowDependDerectionRight = 3
}ArrowDependDerection;
@interface XDYAskRemindView : UIView
/**
初始化方法介绍
@param frame 可以使用masonry后传
@param type view展示方向,可以为横,竖
@param derection 箭头所在方向,上下左右
@param pvalue 箭头在某一方向的位置,如在上下,pvalue为x值,若在左或右,pvalue为y值
@param arr 内容数组,内部为字典结构
@param title 竖直展示时显示的title
@return
*/
-(instancetype)initWithFrame:(CGRect)frame axixWithType:(AskViewShowType)type arrowDepend:(ArrowDependDerection)derection point:(CGFloat)pvalue contentText:(NSArray <NSDictionary *> *)arr title:(NSString *)title;
**.m文件**
--------
@interface XDYAskRemindView()
@property (nonatomic, unsafe_unretained) AskViewShowType askType;
@property (nonatomic, unsafe_unretained) ArrowDependDerection arrowDerection;
@property (nonatomic, unsafe_unretained) CGFloat arrowLocate;
@property (nonatomic, strong) NSArray <NSDictionary *> *contentArray;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, unsafe_unretained) CGPoint arrowP;
@end
@implementation XDYAskRemindView
-(void)drawRect:(CGRect)rect{
// 进入此方法后先画三角形,其他的部分在createview里面画,结构就是一个回字型,里面的口内部是用来画页面,里面口与外面口之间的通道用来挪移三角形的位置
if (_arrowDerection == ArrowDependDerectionTop) {
self.arrowP = CGPointMake(self</