zoukankan      html  css  js  c++  java
  • ios 自顶一个view

    //
    //  YKPopView.m
    //  DrawAnSample
    //
    //  Created by 高顺生 on 15/9/6.
    //  Copyright (c) 2015年 yinyakun. All rights reserved.
    //
    
    #import "YKPopView.h"
    #define MENUGAP 7
    
    @implementation YKPopView
    
    -(instancetype)initWithFrame:(CGRect)frame {
        self = [super initWithFrame:frame];
        if (self) {
            self.backgroundColor = [UIColor clearColor];
        }
        return self;
    }
    
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect {
        // Drawing code
        CGFloat width = rect.size.width;
        CGFloat height = rect.size.height;
        CGFloat radius = 3;
        
        // 获取CGContext,注意UIKit里用的是一个专门的函数
        CGContextRef context = UIGraphicsGetCurrentContext();
        // 移动到初始点
        CGContextMoveToPoint(context, radius, MENUGAP);
        
        // 绘制第1条线和第1个1/4圆弧
        CGContextAddLineToPoint(context, width * 5/6 - 6,MENUGAP);
        CGContextAddLineToPoint(context, width * 5/6,0);
        CGContextAddLineToPoint(context, width  * 5/6 + 6,MENUGAP);
        CGContextAddLineToPoint(context, width - radius, MENUGAP);
        CGContextAddArc(context, width - radius, radius + MENUGAP, radius, -0.5 * M_PI, 0.0, 0);
        
        // 绘制第2条线和第2个1/4圆弧
        CGContextAddLineToPoint(context, width, height - radius - MENUGAP);
        CGContextAddArc(context, width - radius, height - radius - MENUGAP, radius, 0.0, 0.5 * M_PI, 0);
        
        // 绘制第3条线和第3个1/4圆弧
        CGContextAddLineToPoint(context, radius, height - MENUGAP);
        CGContextAddArc(context, radius, height - radius - MENUGAP, radius, 0.5 * M_PI, M_PI, 0);
        
        // 绘制第4条线和第4个1/4圆弧
        CGContextAddLineToPoint(context, 0, radius + MENUGAP);
        CGContextAddArc(context, radius, radius + MENUGAP, radius, M_PI, 1.5 * M_PI, 0);
        
        // 闭合路径
        CGContextClosePath(context);
        
        [[UIColor redColor] setFill];
        CGContextDrawPath(context, kCGPathFill);
    
    }
    

      自定义一个view.

  • 相关阅读:
    系统分析与设计——作业9
    系统分析与设计——作业8
    系统分析与设计——作业7
    系统分析与设计——作业6
    系统分析与设计——作业5
    系统分析与设计——作业4
    从循环添加事件谈起对JS闭包的理解
    对JS prototype的理解
    系统分析与设计——作业2
    JavaScript 预编译(变量提升和函数提升的原理)
  • 原文地址:https://www.cnblogs.com/yinyakun/p/4785670.html
Copyright © 2011-2022 走看看