美文网首页
无标题文章

无标题文章

作者: 15c71b2c9951 | 来源:发表于2015-05-19 22:15 被阅读0次

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

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

    }

    ```

    相关文章

      网友评论

          本文标题:无标题文章

          本文链接:https://www.haomeiwen.com/subject/eabjxttx.html