UIView Border color
2024-10-21 02:56:50
//
// 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
最新文章
- ibatis 和 mybatis
- java集合-HashSet
- 人人都是 DBA(X)资源信息收集脚本汇编
- JSP生成条形码
- Servlet Listener
- 我们都忽略了Html5的力量,如果只看成一种技术就大错特错了!
- Extjs 更新数据集Ext.PagingToolbar的start参数重置的处理
- Seeding--zoj2100
- 201521123022 《Java程序设计》 第十一周学习总结
- Java笔记 (持续更新ing)
- MYSQL忘记root密码后如何修改
- Gradle 1.12用户指南翻译——第二十九章. Checkstyle 插件
- JQuery禁止/恢复按钮readonly和disabled小结
- SQLServer和MySql的区别总结
- WDlinux 修改后台默认8080端口的方法
- CSS实现背景透明而背景上的文字不透明
- (转)ASP.NET(C#)FileUpload实现上传限定类型和大小的文件到服务器
- linux达人养成计划学习笔记(四)—— 压缩命令
- 使用Autolayout xib实现动态高度的TableViewCell
- 5 Dockerfile指令详解 &;&; CMD 指令
热门文章
- Ubuntu下如何禁用IPv6
- ThinkPHP隐藏index.php出现No input file specified的解决方法
- 慕课网java就业班级
- HDU - 5094 Maze(状压+bfs)
- Sharepoint2013搜索学习笔记之设置业务数据内容源(六)
- Intellij IDEA生成JavaDoc(转)
- 萌新笔记之Nim取石子游戏
- jzoj6003. 【THUWC2019模拟2019.1.16】Square (乱搞)
- python入门的基本历程
- Java 多线程高并发编程 笔记(二)