iOS 自定义方法 - 不完整边框
///////////////////////////OC.h//////////////////////////
//
// UIView+FreeBorder.h
// BHBFreeBorder
//
// Created by bihongbo on 15/12/30.
// Copyright © 2015年 bihongbo. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef enum : NSUInteger {
BorderTypeTop,
BorderTypeLeft,
BorderTypeRight,
BorderTypeBottom
} BorderType;
@interface UIView (FreeBorder)
/** 多边框 */
- (void)addBorderWithColor:(UIColor *)color size:(CGFloat)size borderTypes:(NSArray *)types;
/** 单边框 */
- (void)addBorderLayerWithColor:(UIColor *)color size:(CGFloat)size borderType:(BorderType)boderType;
@end
//示例
/// 下上右边框
//[lbl1 addBorderWithColor:[UIColor redColor] size:1 borderTypes:@[@(BorderTypeBottom),@(BorderTypeTop),@(BorderTypeRight)]];
/// 单根边框
//[lbl2 addBorderLayerWithColor:[UIColor greenColor] size:1 borderType:BorderTypeRight];
///////////////////////////OC.m//////////////////////////
//
// UIView+FreeBorder.m
// BHBFreeBorder
//
// Created by bihongbo on 15/12/30.
// Copyright © 2015年 bihongbo. All rights reserved.
//
#import "UIView+FreeBorder.h"
@implementation UIView (FreeBorder)
- (void)addBorderWithColor:(UIColor *)color size:(CGFloat)size borderTypes:(NSArray *)types{
for (int i = 0 ; i < types.count; i ++) {
[self addBorderLayerWithColor:color size:size borderType:[types[i] integerValue]];
}
}
- (void)addBorderLayerWithColor:(UIColor *)color size:(CGFloat)size borderType:(BorderType)boderType{
CALayer * layer = [CALayer layer];
layer.backgroundColor = color.CGColor;
[self.layer addSublayer:layer];
switch (boderType) {
case BorderTypeTop:
layer.frame = CGRectMake(0, 0, self.frame.size.width, size);
break;
case BorderTypeLeft:
layer.frame = CGRectMake(0, 0, size, self.frame.size.height);
break;
case BorderTypeBottom:
layer.frame = CGRectMake(0, self.frame.size.height - size, self.frame.size.width, size);
break;
case BorderTypeRight:
layer.frame = CGRectMake(self.frame.size.width - size, 0, size, self.frame.size.height);
break;
default:
break;
}
}
@end
///////////////////////////Swift//////////////////////////
//
// UIView+FreeBolder.swift
// daydays
//
// Created by bihongbo on 9/14/15.
// Copyright (c) 2015 daydays. All rights reserved.
//
import Foundation
import UIKit
@objc enum BorderType:NSInteger{
case top,left,bottom,right
}
extension UIView{
// MARK: - 为视图加上边框 ,枚举数组可以填充上下左右四个边
@objc func addBorder(color: UIColor?, size: CGFloat, borderTypes:NSArray){
var currentColor:UIColor?
if let _ = color{
currentColor = color
}else{
currentColor = UIColor.blackColor()
}
for borderType in borderTypes{
let bt: NSNumber = borderType as! NSNumber
self.addBorderLayer(currentColor!, size: size, boderType: BorderType(rawValue: bt.integerValue)!)
}
}
@objc func addBorderLayer(color: UIColor, size: CGFloat, boderType: BorderType){
let layer:CALayer = CALayer()
layer.backgroundColor = color.CGColor
self.layer.addSublayer(layer)
switch boderType{
case .top:
layer.frame = CGRectMake(0, 0, self.frame.width, size)
case .left:
layer.frame = CGRectMake(0, 0, size, self.frame.height)
case .bottom:
layer.frame = CGRectMake(0, self.frame.height - size, self.frame.width, size)
case .right:
layer.frame = CGRectMake(self.frame.width - size, 0, size, self.frame.height)
// default:
// return;
}
}
}
//示例
/// 下上右边框
//lbl1.addBorder(UIColor.redColor(), size: 1, borderTypes: [BorderType.bottom.rawValue,BorderType.top.rawValue,BorderType.right.rawValue])
/// 单根边框
//lbl2.addBorderLayer(UIColor.greenColor(), size: 1, boderType: BorderType.right);
iOS 自定义方法 - 不完整边框的更多相关文章
- iOS项目的完整重命名方法图文教程
原文链接:http://www.cocoachina.com/ios/20150104/10824.html iOS项目的完整重命名方法图文教程 前言:在iOS开发中,有时候想改一下项目的名字,都会遇 ...
- IOS UIView圆角,阴影,边框,渐增光泽
圆角 sampleView.layer.cornerRadius = 2.5; // 圓角的弧度sampleView.layer.masksToBounds = YES; 阴影 sampleView. ...
- iPhone 6/plus iOS Safari fieldset border 边框消失
问题:iPhone6 plus 手机浏览网页,fieldset border 边框消失. 示例代码: <div> <fieldset style="border: 1px ...
- IOS设置UIView的边框为圆角
iOS 系统自带的 View 组件都是正方形的,看起来都太生硬,有时候我需要变成圆角形式,如下图: 具体的实现是使用QuartzCore库,下面我具体的描述一下实现过程: • 首先 ...
- iOS 自定义方法 - UIView扩展
示例代码 //#import <UIKit/UIKit.h>@interface UIView (LPCView)/** 上 */@property CGFloat top;/** 下 * ...
- iOS 自定义方法 - 播放GIF
示例代码 ///////////////////////第一种/////////////////////// //// GifView.h// GIFViewer//// Created by ...
- iOS设置分割线从边框顶端开始
好方法,本来是在xib里面设置自定义分割线位置,结果还是差15像素,该方法亲测好使. IOS8 设置TableView Separatorinset 分割线从边框顶端开始 (转) 在ios8上 [Ta ...
- iOS 数据库sqlite完整增删改查操作
1: 创建数据库表格 1.1 — 表格创建使用一个数据库软件快速创建:软件大小14.3M; 下载地址:http://pan.baidu.com/s/1qWOgGoc; 表格创建-> 打开软件,点 ...
- iOS之一个iOS开发人员完整的学习路线
iOS开发能力 掌握(最好是精通)OC语言和runtime各种细节(读过相关的clang源码和runtime源码为佳).精通基本的framework(Foundation,UIKit等,平时干活用得最 ...
随机推荐
- Ajax及跨域
概念 Ajax Ajax,Asynchronous JavaScript and XML,字面意思:异步的 JavaScript 和 XML,是指一种创建交互式网页应用的网页开发技术. 用于异步地去获 ...
- 终于等到你:CYQ.Data V5系列 (ORM数据层)最新版本开源了
前言: 不要问我框架为什么从收费授权转到免费开源,人生没有那么多为什么,这些年我开源的东西并不少,虽然这个是最核心的,看淡了就也没什么了. 群里的网友:太平说: 记得一年前你开源另一个项目的时候我就说 ...
- ASP.NET内置对象的总结
1. Response对象可形象的称之为响应对象,用于将数据从服务器发送回浏览器. 实例源码:链接: http://pan.baidu.com/s/1dDCKQ8x 密码: ihq0 2. Requ ...
- DBA成长路线
从开发转为数据库管理,即人们称为DBA的已经有好几年,有了与当初不一样的体会.数据是企业的血液,数据是石油,数据是一切大数据.云计算的基础.作为DBA是数据的保卫者.管理者,是企业非常重要的角色.对于 ...
- Linux常用命令操作
系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...
- iOS之绘制虚线
/* ** lineFrame: 虚线的 frame ** length: 虚线中短线的宽度 ** spacing: 虚线中短线之间的间距 ** co ...
- MySQL常用命令
数据库登陆命令: mysql -uroot -p 2.提示输入密码: 3.登陆成功: 4.数据库修改相关命令: 修改数据库的编码格式: 语法格式为:ALTER {DATABASE|SCHEMA} [ ...
- 初学DirectX11, 留个纪恋。
以前学的是openGL, 最近才开始学DirectX11,写了个很垃圾的代码,怀念以前的glPushMatrix(), glPopMatrix(), glBegin(), glEnd(), 多简单啊, ...
- 我的MYSQL学习心得(十) 自定义存储过程和函数
我的MYSQL学习心得(十) 自定义存储过程和函数 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心 ...
- 在Linux(Ubuntu/openSUSE/CentOS)下配置ASP.NET(Apache + Mono)
[题外话] 闲的无聊竟然想尝试测试自己做的项目在不同操作系统上的性能表现,所以决定试试在Linux上部署Apache和Mono的环境.由于平时很少接触Linux,所以从网上找了几篇文章(附在相关链接中 ...