无标题文章

一、可翻页的卡片式弹出框的实现

1.首先我们需要自定义绘制一个取消按钮

========

  • 新建一个类QKInfoCardCloseButton继承自UIButton

========

  • 添加属性@property (nonatomic) UIColor *buttonStrokeColor;

=======

  • 实现方法-(instancetype)initWithFrame:(CGRect)frame; -(id)initWithCoder:(NSCoder *)aDecoder -(instancetype)init
-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setUp];
    }
    return self;
}

-(instancetype)init {
    
    return [self initWithFrame:CGRectZero];
}

=======

  • 设置背景色backgroundColor 设置 self.showsTouchWhenHighlighted = YES;
- (void)setUp {
    
    self.backgroundColor = [UIColor whiteColor];
    
    self.showsTouchWhenHighlighted = YES;
}

=======

  • 重写- (void)drawRect:(CGRect)rect来绘制按钮

2.新建一个类QKInfoCardContainerView继承自UIView用来实现显示区域

  • 添加以下属性

=====

@property (assign, nonatomic) CGFloat cornerRadius;//显示区域的圆角

@property (strong, nonatomic) UIColor *containerBackgroundColor;//显示区域的背景色

@property (strong, nonatomic) UIColor *closeButtonTintColor;//关闭按钮的线条颜色

@property (strong, nonatomic) UIColor *closeButtonBackgroundColor;//关闭按钮的背景色

@property (strong, nonatomic) NSArray *containtViews;//用来展示的子控制器
  • 添加私有属性
@implementation QKInfoCardContainerView {
    QKInfoCardCloseButton *_closeButton;//关闭按钮
    UIView *_containerView;//展示视图
    UIScrollView *_scrollView;
}
  • 同样去实现三个构造方法

===

-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}

-(id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setUp];
    }
    return self;
}

-(instancetype)init {
    return [self initWithFrame:CGRectZero];
}

你可能感兴趣的:(无标题文章)