UIView分類,OC、swift雙語,自由添加四周邊框:BHBFreeBorder

jopen 8年前發布 | 26K 次閱讀 iOS開發 移動開發 BHBFreeBorder

BHBFreeBorder

UIView分類,OC、swift雙語,自由添加四周邊框,顏色粗細隨心所欲(^_^)

效果圖

效果圖

使用方法

1.導入UIView+BHBFreeBorder分類

2.添加單根邊框,例如只加右邊框

OC:

    /// 單根邊框
    UILabel * lbl2 = [[UILabel alloc] init];
    lbl2.frame = CGRectMake(50, 250, 100, 50);
    [self.view addSubview:lbl2];
    [lbl2 addBorderLayerWithColor:[UIColor greenColor] size:1 borderType:BorderTypeRight];

swift:

/// 單根邊框
    let lbl2:UILabel = UILabel()
    lbl2.frame = CGRectMake(50, 250, 100, 50)
    self.view.addSubview(lbl2)
    lbl2.addBorderLayer(UIColor.greenColor(), size: 1, boderType: BorderType.right);

3.添加n根邊框,代碼如下:

OC:

    /// 下上左邊框
    UILabel * lbl = [[UILabel alloc] init];
    lbl.frame = CGRectMake(50, 50, 100, 50);
    [self.view addSubview:lbl];
    [lbl addBorderWithColor:[UIColor redColor] size:1 borderTypes:@[@(BorderTypeBottom),@(BorderTypeTop),@(BorderTypeLeft)]];
    /// 下上右邊框
    UILabel * lbl1 = [[UILabel alloc] init];
    lbl1.frame = CGRectMake(50, 150, 100, 50);
    [self.view addSubview:lbl1];
    [lbl1 addBorderWithColor:[UIColor redColor] size:1 borderTypes:@[@(BorderTypeBottom),@(BorderTypeTop),@(BorderTypeRight)]];

swift:

     /// 下上左邊框
    let lbl:UILabel = UILabel()
    lbl.frame = CGRectMake(50, 50, 100, 50)
    self.view.addSubview(lbl)
    lbl.addBorder(UIColor.redColor(), size: 1, borderTypes: [BorderType.bottom.rawValue,BorderType.top.rawValue,BorderType.left.rawValue])
    /// 下上右邊框
    let lbl1:UILabel = UILabel()
    lbl1.frame = CGRectMake(50, 150, 100, 50)
    self.view.addSubview(lbl1)
    lbl1.addBorder(UIColor.redColor(), size: 1, borderTypes: [BorderType.bottom.rawValue,BorderType.top.rawValue,BorderType.right.rawValue])

大家玩的開心,good luck!

項目地址: https://github.com/bb-coder/BHBFreeBorder

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!