無標題文章

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

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

}

```

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

推薦閱讀更多精彩內容

  • ####一、可翻頁的卡片式彈出框的實現 1.**首先我們需要自定義繪制一個取消按鈕** ======== * 新建...
    15c71b2c9951閱讀 198評論 0 1
  • 1、設置UILabel行間距 NSMutableAttributedString*attrString=[[NSM...
    iOS祎閱讀 2,222評論 0 0
  • 轉至元數據結尾創建: 董瀟偉,最新修改于: 十二月 23, 2016 轉至元數據起始第一章:isa和Class一....
    40c0490e5268閱讀 1,788評論 0 9
  • 【2017年最新】? iOS面試題及答案 設計模式是什么? 你知道哪些設計模式,并簡要敘述? 設計模式是一種編碼經...
    紫色冰雨閱讀 624評論 0 1
  • 堅持冥想100天,養成習慣,讓冥想與自己的生活融為一體。 打卡第22天 時長:16分鐘 感悟:在凳子上坐直冥想。本...
    愛做瑜伽的小兔子閱讀 656評論 2 4