####一、可翻頁的卡片式彈出框的實現
1.**首先我們需要自定義繪制一個取消按鈕**
========
* 新建一個類`QKInfoCardCloseButton`繼承自UIButton
========
* 添加屬性```@property (nonatomic) UIColor *buttonStrokeColor; ```
=======
* 實現方法`-(instancetype)initWithFrame:(CGRect)frame;` `-(id)initWithCoder:(NSCoder *)aDecoder` `-(instancetype)init`
```objective-c
-(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;`
```objective-c
- (void)setUp {
self.backgroundColor = [UIColor whiteColor];
self.showsTouchWhenHighlighted = YES;
}
```
=======
* 重寫`- (void)drawRect:(CGRect)rect`來繪制按鈕
2.**新建一個類`QKInfoCardContainerView`繼承自UIView用來實現顯示區域**
* 添加以下屬性
=====
```objective-c
@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;//用來展示的子控制器
```
* 添加私有屬性
```objective-c
@implementation QKInfoCardContainerView {
QKInfoCardCloseButton *_closeButton;//關閉按鈕
UIView *_containerView;//展示視圖
UIScrollView *_scrollView;
}
```
* 同樣去實現三個構造方法
===
```objective-c
-(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];
}
```