無標題文章

####一、可翻頁的卡片式彈出框的實現

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];

}

```

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容