//
// UIView+Borders.h
//
// Created by Aaron Ng on 12/28/13.
// Copyright (c) 2013 Delve. All rights reserved.
// #import <UIKit/UIKit.h> @interface UIView (Borders) /* Create your borders and assign them to a property on a view when you can via the create methods when possible. Otherwise you might end up with multiple borders being created.
*/ ///------------
/// Top Border
///------------
-(CALayer*)createTopBorderWithHeight: (CGFloat)height andColor:(UIColor*)color;
-(UIView*)createViewBackedTopBorderWithHeight: (CGFloat)height andColor:(UIColor*)color;
-(void)addTopBorderWithHeight:(CGFloat)height andColor:(UIColor*)color;
-(void)addViewBackedTopBorderWithHeight:(CGFloat)height andColor:(UIColor*)color; ///------------
/// Top Border + Offsets
///------------ -(CALayer*)createTopBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andTopOffset:(CGFloat)topOffset;
-(UIView*)createViewBackedTopBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andTopOffset:(CGFloat)topOffset;
-(void)addTopBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andTopOffset:(CGFloat)topOffset;
-(void)addViewBackedTopBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andTopOffset:(CGFloat)topOffset; ///------------
/// Right Border
///------------ -(CALayer*)createRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color;
-(UIView*)createViewBackedRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color;
-(void)addRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color;
-(void)addViewBackedRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color; ///------------
/// Right Border + Offsets
///------------ -(CALayer*)createRightBorderWithWidth: (CGFloat)width color:(UIColor*)color rightOffset:(CGFloat)rightOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset;
-(UIView*)createViewBackedRightBorderWithWidth: (CGFloat)width color:(UIColor*)color rightOffset:(CGFloat)rightOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset;
-(void)addRightBorderWithWidth: (CGFloat)width color:(UIColor*)color rightOffset:(CGFloat)rightOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset;
-(void)addViewBackedRightBorderWithWidth: (CGFloat)width color:(UIColor*)color rightOffset:(CGFloat)rightOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset; ///------------
/// Bottom Border
///------------ -(CALayer*)createBottomBorderWithHeight: (CGFloat)height andColor:(UIColor*)color;
-(UIView*)createViewBackedBottomBorderWithHeight: (CGFloat)height andColor:(UIColor*)color;
-(void)addBottomBorderWithHeight:(CGFloat)height andColor:(UIColor*)color;
-(void)addViewBackedBottomBorderWithHeight:(CGFloat)height andColor:(UIColor*)color; ///------------
/// Bottom Border + Offsets
///------------ -(CALayer*)createBottomBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andBottomOffset:(CGFloat)bottomOffset;
-(UIView*)createViewBackedBottomBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andBottomOffset:(CGFloat)bottomOffset;
-(void)addBottomBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andBottomOffset:(CGFloat)bottomOffset;
-(void)addViewBackedBottomBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andBottomOffset:(CGFloat)bottomOffset; ///------------
/// Left Border
///------------ -(CALayer*)createLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color;
-(UIView*)createViewBackedLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color;
-(void)addLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color;
-(void)addViewBackedLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color; ///------------
/// Left Border + Offsets
///------------ -(CALayer*)createLeftBorderWithWidth: (CGFloat)width color:(UIColor*)color leftOffset:(CGFloat)leftOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset;
-(UIView*)createViewBackedLeftBorderWithWidth: (CGFloat)width color:(UIColor*)color leftOffset:(CGFloat)leftOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset;
-(void)addLeftBorderWithWidth: (CGFloat)width color:(UIColor*)color leftOffset:(CGFloat)leftOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset;
-(void)addViewBackedLeftBorderWithWidth: (CGFloat)width color:(UIColor*)color leftOffset:(CGFloat)leftOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset; @end
//
// UIView+Borders.m
//
// Created by Aaron Ng on 12/28/13.
// Copyright (c) 2013 Delve. All rights reserved.
// #import "UIView+Borders.h" @implementation UIView(Borders) //////////
// Top
////////// -(CALayer*)createTopBorderWithHeight: (CGFloat)height andColor:(UIColor*)color{
return [self getOneSidedBorderWithFrame:CGRectMake(, , self.frame.size.width, height) andColor:color];
} -(UIView*)createViewBackedTopBorderWithHeight: (CGFloat)height andColor:(UIColor*)color{
return [self getViewBackedOneSidedBorderWithFrame:CGRectMake(, , self.frame.size.width, height) andColor:color];
} -(void)addTopBorderWithHeight: (CGFloat)height andColor:(UIColor*)color{
[self addOneSidedBorderWithFrame:CGRectMake(, , self.frame.size.width, height) andColor:color];
} -(void)addViewBackedTopBorderWithHeight: (CGFloat)height andColor:(UIColor*)color{
[self addViewBackedOneSidedBorderWithFrame:CGRectMake(, , self.frame.size.width, height) andColor:color];
} //////////
// Top + Offset
////////// -(CALayer*)createTopBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andTopOffset:(CGFloat)topOffset {
// Subtract the bottomOffset from the height and the thickness to get our final y position.
// Add a left offset to our x to get our x position.
// Minus our rightOffset and negate the leftOffset from the width to get our endpoint for the border.
return [self getOneSidedBorderWithFrame:CGRectMake( + leftOffset, + topOffset, self.frame.size.width - leftOffset - rightOffset, height) andColor:color];
} -(UIView*)createViewBackedTopBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andTopOffset:(CGFloat)topOffset {
return [self getViewBackedOneSidedBorderWithFrame:CGRectMake( + leftOffset, + topOffset, self.frame.size.width - leftOffset - rightOffset, height) andColor:color];
} -(void)addTopBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andTopOffset:(CGFloat)topOffset {
// Add leftOffset to our X to get start X position.
// Add topOffset to Y to get start Y position
// Subtract left offset from width to negate shifting from leftOffset.
// Subtract rightoffset from width to set end X and Width.
[self addOneSidedBorderWithFrame:CGRectMake( + leftOffset, + topOffset, self.frame.size.width - leftOffset - rightOffset, height) andColor:color];
} -(void)addViewBackedTopBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andTopOffset:(CGFloat)topOffset {
[self addViewBackedOneSidedBorderWithFrame:CGRectMake( + leftOffset, + topOffset, self.frame.size.width - leftOffset - rightOffset, height) andColor:color];
} //////////
// Right
////////// -(CALayer*)createRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color{
return [self getOneSidedBorderWithFrame:CGRectMake(self.frame.size.width-width, , width, self.frame.size.height) andColor:color];
} -(UIView*)createViewBackedRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color{
return [self getViewBackedOneSidedBorderWithFrame:CGRectMake(self.frame.size.width-width, , width, self.frame.size.height) andColor:color];
} -(void)addRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color{
[self addOneSidedBorderWithFrame:CGRectMake(self.frame.size.width-width, , width, self.frame.size.height) andColor:color];
} -(void)addViewBackedRightBorderWithWidth: (CGFloat)width andColor:(UIColor*)color{
[self addViewBackedOneSidedBorderWithFrame:CGRectMake(self.frame.size.width-width, , width, self.frame.size.height) andColor:color];
} //////////
// Right + Offset
////////// -(CALayer*)createRightBorderWithWidth: (CGFloat)width color:(UIColor*)color rightOffset:(CGFloat)rightOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset{ // Subtract bottomOffset from the height to get our end.
return [self getOneSidedBorderWithFrame:CGRectMake(self.frame.size.width-width-rightOffset, + topOffset, width, self.frame.size.height - topOffset - bottomOffset) andColor:color];
} -(UIView*)createViewBackedRightBorderWithWidth: (CGFloat)width color:(UIColor*)color rightOffset:(CGFloat)rightOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset{
return [self getViewBackedOneSidedBorderWithFrame:CGRectMake(self.frame.size.width-width-rightOffset, + topOffset, width, self.frame.size.height - topOffset - bottomOffset) andColor:color];
} -(void)addRightBorderWithWidth: (CGFloat)width color:(UIColor*)color rightOffset:(CGFloat)rightOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset{ // Subtract the rightOffset from our width + thickness to get our final x position.
// Add topOffset to our y to get our start y position.
// Subtract topOffset from our height, so our border doesn't extend past teh view.
// Subtract bottomOffset from the height to get our end.
[self addOneSidedBorderWithFrame:CGRectMake(self.frame.size.width-width-rightOffset, + topOffset, width, self.frame.size.height - topOffset - bottomOffset) andColor:color];
} -(void)addViewBackedRightBorderWithWidth: (CGFloat)width color:(UIColor*)color rightOffset:(CGFloat)rightOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset{
[self addViewBackedOneSidedBorderWithFrame:CGRectMake(self.frame.size.width-width-rightOffset, + topOffset, width, self.frame.size.height - topOffset - bottomOffset) andColor:color];
} //////////
// Bottom
////////// -(CALayer*)createBottomBorderWithHeight: (CGFloat)height andColor:(UIColor*)color{
return [self getOneSidedBorderWithFrame:CGRectMake(, self.frame.size.height-height, self.frame.size.width, height) andColor:color];
} -(UIView*)createViewBackedBottomBorderWithHeight: (CGFloat)height andColor:(UIColor*)color{
return [self getViewBackedOneSidedBorderWithFrame:CGRectMake(, self.frame.size.height-height, self.frame.size.width, height) andColor:color];
} -(void)addBottomBorderWithHeight: (CGFloat)height andColor:(UIColor*)color{
[self addOneSidedBorderWithFrame:CGRectMake(, self.frame.size.height-height, self.frame.size.width, height) andColor:color];
} -(void)addViewBackedBottomBorderWithHeight: (CGFloat)height andColor:(UIColor*)color{
[self addViewBackedOneSidedBorderWithFrame:CGRectMake(, self.frame.size.height-height, self.frame.size.width, height) andColor:color];
} //////////
// Bottom + Offset
////////// -(CALayer*)createBottomBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andBottomOffset:(CGFloat)bottomOffset {
// Subtract the bottomOffset from the height and the thickness to get our final y position.
// Add a left offset to our x to get our x position.
// Minus our rightOffset and negate the leftOffset from the width to get our endpoint for the border.
return [self getOneSidedBorderWithFrame:CGRectMake( + leftOffset, self.frame.size.height-height-bottomOffset, self.frame.size.width - leftOffset - rightOffset, height) andColor:color];
} -(UIView*)createViewBackedBottomBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andBottomOffset:(CGFloat)bottomOffset{
return [self getViewBackedOneSidedBorderWithFrame:CGRectMake( + leftOffset, self.frame.size.height-height-bottomOffset, self.frame.size.width - leftOffset - rightOffset, height) andColor:color];
} -(void)addBottomBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andBottomOffset:(CGFloat)bottomOffset {
// Subtract the bottomOffset from the height and the thickness to get our final y position.
// Add a left offset to our x to get our x position.
// Minus our rightOffset and negate the leftOffset from the width to get our endpoint for the border.
[self addOneSidedBorderWithFrame:CGRectMake( + leftOffset, self.frame.size.height-height-bottomOffset, self.frame.size.width - leftOffset - rightOffset, height) andColor:color];
} -(void)addViewBackedBottomBorderWithHeight: (CGFloat)height color:(UIColor*)color leftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset andBottomOffset:(CGFloat)bottomOffset{
[self addViewBackedOneSidedBorderWithFrame:CGRectMake( + leftOffset, self.frame.size.height-height-bottomOffset, self.frame.size.width - leftOffset - rightOffset, height) andColor:color];
} //////////
// Left
////////// -(CALayer*)createLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color{
return [self getOneSidedBorderWithFrame:CGRectMake(, , width, self.frame.size.height) andColor:color];
} -(UIView*)createViewBackedLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color{
return [self getViewBackedOneSidedBorderWithFrame:CGRectMake(, , width, self.frame.size.height) andColor:color];
} -(void)addLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color{
[self addOneSidedBorderWithFrame:CGRectMake(, , width, self.frame.size.height) andColor:color];
} -(void)addViewBackedLeftBorderWithWidth: (CGFloat)width andColor:(UIColor*)color{
[self addViewBackedOneSidedBorderWithFrame:CGRectMake(, , width, self.frame.size.height) andColor:color];
} //////////
// Left + Offset
////////// -(CALayer*)createLeftBorderWithWidth: (CGFloat)width color:(UIColor*)color leftOffset:(CGFloat)leftOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset {
return [self getOneSidedBorderWithFrame:CGRectMake( + leftOffset, + topOffset, width, self.frame.size.height - topOffset - bottomOffset) andColor:color];
} -(UIView*)createViewBackedLeftBorderWithWidth: (CGFloat)width color:(UIColor*)color leftOffset:(CGFloat)leftOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset{
return [self getViewBackedOneSidedBorderWithFrame:CGRectMake( + leftOffset, + topOffset, width, self.frame.size.height - topOffset - bottomOffset) andColor:color];
} -(void)addLeftBorderWithWidth: (CGFloat)width color:(UIColor*)color leftOffset:(CGFloat)leftOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset {
[self addOneSidedBorderWithFrame:CGRectMake( + leftOffset, + topOffset, width, self.frame.size.height - topOffset - bottomOffset) andColor:color];
} -(void)addViewBackedLeftBorderWithWidth: (CGFloat)width color:(UIColor*)color leftOffset:(CGFloat)leftOffset topOffset:(CGFloat)topOffset andBottomOffset:(CGFloat)bottomOffset{
[self addViewBackedOneSidedBorderWithFrame:CGRectMake( + leftOffset, + topOffset, width, self.frame.size.height - topOffset - bottomOffset) andColor:color];
} //////////
// Private: Our methods call these to add their borders.
////////// -(void)addOneSidedBorderWithFrame:(CGRect)frame andColor:(UIColor*)color
{
CALayer *border = [CALayer layer];
border.frame = frame;
[border setBackgroundColor:color.CGColor];
[self.layer addSublayer:border];
} -(CALayer*)getOneSidedBorderWithFrame:(CGRect)frame andColor:(UIColor*)color
{
CALayer *border = [CALayer layer];
border.frame = frame;
[border setBackgroundColor:color.CGColor];
return border;
} -(void)addViewBackedOneSidedBorderWithFrame:(CGRect)frame andColor:(UIColor*)color
{
UIView *border = [[UIView alloc]initWithFrame:frame];
[border setBackgroundColor:color];
[self addSubview:border];
} -(UIView*)getViewBackedOneSidedBorderWithFrame:(CGRect)frame andColor:(UIColor*)color
{
UIView *border = [[UIView alloc]initWithFrame:frame];
[border setBackgroundColor:color];
return border;
} @end

UIView Border color的更多相关文章

  1. CSS3详解:border color

    继续我们的 ,大家觉得怎么样呢?

  2. UIView简单动画

    UIView动态实现的效果有以下几种: 1.动态改变frame 2.动态改变color 3.动态改变alpha 4.动态改变bounds 首先,我们先看几种BasicView动画 #pragma ma ...

  3. LeetCode 1034. Coloring A Border

    原题链接在这里:https://leetcode.com/problems/coloring-a-border/ 题目: Given a 2-dimensional grid of integers, ...

  4. Quartz2D之生成圆形头像、打水印、截图三种方法的封装

    我给UIImage类添加了一个类目,用于封装三个方法,每个方法都没有难度,做这个主要为了练习一下封装: 首先在类目.h文件中声明三个方法:以及创建了一个枚举.用于水印方法中设定水印位置:方法说明和参数 ...

  5. 【转】UINavigationBar 使用总结

    原文网址:http://www.jianshu.com/p/f0d3df54baa6 UINavigationBar是我们在开发过程中经常要用到的一个控件,下面我会为大家介绍一些常用的用法. 1. 设 ...

  6. Scroll Segmented Control(Swift)

    今天用了一个github上一个比较好用的Segmented Control但是发现不是我要效果,我需要支持scrollView.当栏目数量超过一屏幕,需要能够滑动. 由于联系作者没有回复,我就自己在其 ...

  7. RDMBorderedButton

    RDMBorderedButton https://github.com/reesemclean/RDMBorderedButton 效果: 源码: RDMBorderedButton.h + RDM ...

  8. Chisel常用命令总结

    Chisel简介 Chisel是Facebook开源的一款lldb调试工具,其实就是对系统lldb命令的封装,开发者可以通过简化的命令更方便的进行调试工作.开源地址:https://github.co ...

  9. iOSQuart2D绘图之UIImage简单使用

    代码地址如下:http://www.demodashi.com/demo/11609.html 人生得意须尽欢,莫使金樽空对月. 天生我材必有用,千金散尽还复来. 前记 说到UIImage大家都不会感 ...

随机推荐

  1. Acdream手速赛7

    蛋疼啊,本次只做出了一道题目...渣爆了... 妈蛋,,卡题之夜..比赛结果是1道题,比赛完哗啦哗啦出4道题.. A acdream1191 Dragon Maze 题意: 给一个迷宫,给出入口坐标和 ...

  2. JavaScript代码放在HTML代码不同位置的差别

    通常情况下,JavaScript 代码是和 HTML 代码一起使用的,可以将 JavaScript 代码放置在 HTML 文档的任何地方.但放置的地方,会对 JavaScript 代码的正常执行会有一 ...

  3. MYSQL limit,offset 区别(转)

    SELECT keyword FROM keyword_rank WHERE advertiserid='59' order by keyword LIMIT 2 OFFSET 1; 比如这个SQL ...

  4. cf769D(枚举&位或运算)

    题目链接:http://codeforces.com/problemset/problem/769/D 题意:求给出的 n 个数中有多少对数字的二进制形式恰好有 k 位不同 思路:两个数a, b的二进 ...

  5. js中的原型以及原型链

    在js中原型是每个构造函数的属性: 这个算 js 核心概念的一部分 var f1 = new Foo(); 对象 f1 的构造函数就是 Foo , f1的原型 __proto__ 就指向构造函数 Fo ...

  6. 基础篇-密码文件.pgpass

    密码文件包含字段 host:port:dbname:user:password port和dbname可以使用*号作通配符 在*nix系统中 ~/.pgpass 在windows系统中 %APPDAT ...

  7. 深入理解JVM的类加载

    前言: 前面又说到Java程序实际上是将.class文件放入JVM中运行.虚拟机把描述类的数据从Class文件加载到内存,并对数据进行校验,转换,解析和初始化,最终形成可以被虚拟机直接使用的Java类 ...

  8. Java进程占用内存过高,排查解决方法

    最近收到邮件报警,说内存使作率达到84%.如下图: 解决方法: A:可能是代码原因导致的问题: 1.使用命令:top 查看当前进程的状态 2.从上图可以看到PID:916的java进程占用内存较大.定 ...

  9. 源码分析(一) 进程cleos的命令解析

    EOS版本:4.0   一.进程cleos的作用   cleos,即为client eos.从名字就可以猜出来,它是一个标准的客户端程序,而实际上,它也确实为一个标准的client^_^   准确地说 ...

  10. vue之webpack打包工具的使用

    vue之webpack打包工具的使用 一.什么是webpack? webpack是一个模块打包工具.用vue项目来举例:浏览器它是只认识js,不认识vue的.而我们写的代码后缀大多是.vue的,在每个 ...