UIView Border color
//
// 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的更多相关文章
- CSS3详解:border color
继续我们的 ,大家觉得怎么样呢?
- UIView简单动画
UIView动态实现的效果有以下几种: 1.动态改变frame 2.动态改变color 3.动态改变alpha 4.动态改变bounds 首先,我们先看几种BasicView动画 #pragma ma ...
- LeetCode 1034. Coloring A Border
原题链接在这里:https://leetcode.com/problems/coloring-a-border/ 题目: Given a 2-dimensional grid of integers, ...
- Quartz2D之生成圆形头像、打水印、截图三种方法的封装
我给UIImage类添加了一个类目,用于封装三个方法,每个方法都没有难度,做这个主要为了练习一下封装: 首先在类目.h文件中声明三个方法:以及创建了一个枚举.用于水印方法中设定水印位置:方法说明和参数 ...
- 【转】UINavigationBar 使用总结
原文网址:http://www.jianshu.com/p/f0d3df54baa6 UINavigationBar是我们在开发过程中经常要用到的一个控件,下面我会为大家介绍一些常用的用法. 1. 设 ...
- Scroll Segmented Control(Swift)
今天用了一个github上一个比较好用的Segmented Control但是发现不是我要效果,我需要支持scrollView.当栏目数量超过一屏幕,需要能够滑动. 由于联系作者没有回复,我就自己在其 ...
- RDMBorderedButton
RDMBorderedButton https://github.com/reesemclean/RDMBorderedButton 效果: 源码: RDMBorderedButton.h + RDM ...
- Chisel常用命令总结
Chisel简介 Chisel是Facebook开源的一款lldb调试工具,其实就是对系统lldb命令的封装,开发者可以通过简化的命令更方便的进行调试工作.开源地址:https://github.co ...
- iOSQuart2D绘图之UIImage简单使用
代码地址如下:http://www.demodashi.com/demo/11609.html 人生得意须尽欢,莫使金樽空对月. 天生我材必有用,千金散尽还复来. 前记 说到UIImage大家都不会感 ...
随机推荐
- 实现一个排序,要求时间效率O(n)
数据大小是在一个范围内的,可以使用常量大小的辅助空间.不得超过O(n); #include "stdafx.h" #include <iostream> #includ ...
- DSOFramer控件使用注意事项
1.引用dll==>AxInterop.DSOFramer.dll ==>Interop.DSOFramer.dll ==>WindowsFormsIntegration ==> ...
- 《剑指offer》面试题8—旋转数组的最小数字
题目:把一个数组最开始的若干个元素搬到数组末尾我们称之为数组的旋转.要求:输入一个递增排序的数组的旋转,输出旋转数组中的最小数字.例如{3,4,5,1,2}是{1,2,3,4,5}的一个旋转,该数组的 ...
- 327. Count of Range Sum(inplace_marge)
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...
- TensorFlow中tf.ConfigProto()配置Sesion运算方式
博主个人网站:https://chenzhen.online tf.configProto用于在创建Session的时候配置Session的运算方式,即使用GPU运算或CPU运算: 1. tf.Con ...
- Android权限之三共享UID和签名
http://blog.csdn.net/a345017062/article/details/6236263 共享UID 安装在设备中的每一个Android包文件(.apk)都会被分配到一个属于自己 ...
- 洛谷P1868 饥饿的奶牛
P1868 饥饿的奶牛 题目描述 有一条奶牛冲出了围栏,来到了一处圣地(对于奶牛来说),上面用牛语写着一段文字. 现用汉语翻译为: 有N个区间,每个区间x,y表示提供的x~y共y-x+1堆优质牧草.你 ...
- Django + Vue cli 3.0 访问静态资源问题
[问题背景] 用Vue clie 3.0的搭建得框架把我坑死了,在打包后,调用不到静态资源js,css,mp3等 [问题原因] vue cli 3.0打包后,dist目录下没有static目录,而Dj ...
- eclipse for php 开发环境配置
PHP有非常多相当不错的开发工具,如Zend Studio.NetBeans.phpdesigner等,但对于习惯Java编程的程序员们来说,下面介绍最经常使用的还要属Eclipse. > 我们 ...
- Codeforces 163C(实数环上的差分计数)
要点 都在注释里了 #include <cstdio> #include <cstring> #include <iostream> #include <al ...