zoukankan      html  css  js  c++  java
  • iOS给一个view添加虚线边框

    /**

     * 此方法作用:给一个矩形视图增加四条矩形虚线边框

     *

     * parma:superView:需要加载的父视图

     */

    #define padding 20

     

    - (void)addDottedLineFromImageView:(UIView *)superView{

        CGFloat w = superView.frame.size.width;

        CGFloat h = superView.frame.size.height;

        

    //创建四个imageView作边框

        for (NSInteger i = 0; i<4; i++) {

            UIImageView *imageView = [[UIImageView alloc] init];

       imageView.backgroundColor = [UIColor clearColor];

            if (i == 0) {

                imageView.frame = CGRectMake(0, 0, w, padding);

            }else if (i == 1){

                imageView.frame = CGRectMake(0, 0, padding, h);

            }else if (i == 2){

                imageView.frame = CGRectMake(0, h - padding, w, padding);

            }else if (i == 3){

                imageView.frame = CGRectMake(w - padding, 0, padding, h);

            }

            [superView addSubview:imageView];

            

            UIGraphicsBeginImageContext(imageView.frame.size);   //开始画线

            [imageView.image drawInRect:CGRectMake(0, 0, imageView.frame.size.width, imageView.frame.size.height)];

            CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);  //设置线条终点形状

            

            CGFloat lengths[] = {10,5};

            CGContextRef line = UIGraphicsGetCurrentContext();

            CGContextSetStrokeColorWithColor(line, [UIColor blackColor].CGColor);

            CGContextSetLineDash(line, 0, lengths, 2);  //画虚线 

            CGContextMoveToPoint(line, 0, 0);    //开始画线

            

            if (i == 0) {

                CGContextAddLineToPoint(line, w - padding, 0);

            }else if (i == 1){

                CGContextAddLineToPoint(line, 0, w);

            }else if (i == 2){

                CGContextMoveToPoint(line, 0, padding);

                CGContextAddLineToPoint(line, w, padding);

            }else if (i == 3){

                CGContextMoveToPoint(line, padding, 0);

                CGContextAddLineToPoint(line, padding, w);

            }

            

            CGContextStrokePath(line);

            imageView.image = UIGraphicsGetImageFromCurrentImageContext();

        }

    }

  • 相关阅读:
    [arc067F]Yakiniku Restaurants[矩阵差分]
    [2016北京集训测试赛3]masodik-[凸包]
    [WC2010][BZOJ1758]重建计划-[二分+分数规划+点分治]
    [2016北京集训测试赛7]isn-[树状数组+dp+容斥]
    [BZOJ1565][NOI2009]植物大战僵尸-[网络流-最小割+最大点权闭合子图+拓扑排序]
    [2016北京集训试题7]thr-[树形dp+树链剖分+启发式合并]
    [2016北京集训测试赛1]奇怪的树-[树链剖分]
    [2016北京集训测试赛1]兔子的字符串-[后缀数组+二分]
    模拟 [Sdoi2010]猪国杀
    DP 小奇挖矿2
  • 原文地址:https://www.cnblogs.com/chenjie-ios/p/4709818.html
Copyright © 2011-2022 走看看