为了便于日常开发效率,因此创建了一些小的工具类便于使用.
具体 code 如下:
声明:

/*
为控件添加边框样式_工具类
*/
#import <UIKit/UIKit.h> typedef NS_ENUM(NSInteger,LQQSideType) {
kLQQSideTypeTop = 0,
kLQQSideTypeLeft = 1,
kLQQSideTypeBottom = 2,
kLQQSideTypeRight = 3,
kLQQSideTypeAll = 4,
}; typedef NS_ENUM(NSInteger,LQQSideAngleType) {
kLQQSideAngleTypeTopLeft = 0,
kLQQSideAngleTypeTopRight = 1,
kLQQSideAngleTypeBottomLeft = 2,
kLQQSideAngleTypeBottomRight = 3,
kLQQSideAngleTypeAll = 4,
}; @interface UIView (FYH) /**
设置不同边的圆角
@param sideType 圆角类型
@param cornerRadius 圆角半径
*/
- (void)cornerSideType:(LQQSideType)sideType withCornerRadius:(CGFloat)cornerRadius; /**
设置不同角的圆角
@param sideType 圆角类型
@param cornerRadius 圆角半径
*/
- (void)cornerSideAngleType:(LQQSideAngleType)sideType withCornerRadius:(CGFloat)cornerRadius; /**
设置view某一边框
@param sideType 哪个边
@param color 边框颜色
@param width 边框宽度
*/
- (void)cornerSideType:(LQQSideType)sideType lineColor:(UIColor *)color lineWidth:(CGFloat)width; @end

  

实现:

#import "UIView+FYH.h"

@implementation UIView (FYH)

- (void)cornerSideType:(LQQSideType)sideType withCornerRadius:(CGFloat)cornerRadius
{
CGSize cornerSize = CGSizeMake(cornerRadius, cornerRadius);
UIBezierPath *maskPath; switch (sideType) {
case kLQQSideTypeTop:
{
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
cornerRadii:cornerSize];
}
break;
case kLQQSideTypeLeft:
{
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomLeft)
cornerRadii:cornerSize];
}
break;
case kLQQSideTypeBottom:
{
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight)
cornerRadii:cornerSize];
}
break;
case kLQQSideTypeRight:
{
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopRight|UIRectCornerBottomRight)
cornerRadii:cornerSize];
}
break;
default:
{
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:cornerSize];
}
break;
} // Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath; // Set the newly created shape layer as the mask for the image view's layer
self.layer.mask = maskLayer; [self.layer setMasksToBounds:YES];
} - (void)cornerSideAngleType:(LQQSideAngleType)sideType withCornerRadius:(CGFloat)cornerRadius
{
CGSize cornerSize = CGSizeMake(cornerRadius, cornerRadius);
UIBezierPath *maskPath; switch (sideType) {
case kLQQSideAngleTypeTopLeft:
{
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft)
cornerRadii:cornerSize];
}
break;
case kLQQSideAngleTypeTopRight:
{
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopRight)
cornerRadii:cornerSize];
}
break;
case kLQQSideAngleTypeBottomLeft:
{
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerBottomLeft)
cornerRadii:cornerSize];
}
break;
case kLQQSideAngleTypeBottomRight:
{
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerBottomRight)
cornerRadii:cornerSize];
}
break;
default:
{
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:cornerSize];
}
break;
} // Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath; // Set the newly created shape layer as the mask for the image view's layer
self.layer.mask = maskLayer; [self.layer setMasksToBounds:YES];
} - (void)cornerSideType:(LQQSideType)sideType lineColor:(UIColor *)color lineWidth:(CGFloat)width
{
CAShapeLayer *layer = [CAShapeLayer layer];
UIBezierPath *aPath = [UIBezierPath bezierPath]; switch (sideType) {
case kLQQSideTypeTop:
{
[aPath moveToPoint:CGPointMake(0.0, 0.0)];
[aPath addLineToPoint:CGPointMake(self.frame.size.width, 0.0)];
}
break;
case kLQQSideTypeLeft:
{
[aPath moveToPoint:CGPointMake(0.0, 0.0)];
[aPath addLineToPoint:CGPointMake(0.0, self.frame.size.height)];
}
break;
case kLQQSideTypeBottom:
{
[aPath moveToPoint:CGPointMake(0.0, self.frame.size.height)];
[aPath addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height)];
}
break;
case kLQQSideTypeRight:
{
[aPath moveToPoint:CGPointMake(self.frame.size.width,0.0)];
[aPath addLineToPoint:CGPointMake(self.frame.size.width, self.frame.size.height)]; }
break;
default:
{ }
break;
} layer.path = aPath.CGPath;
layer.strokeColor = color.CGColor;
layer.lineWidth = width;
[self.layer addSublayer:layer];
} @end

 

以上便是此次分享的内容,期待大神多多指点补充,使其更加强壮!

工具类(为控件设置圆角) - iOS的更多相关文章

  1. 工具类(为控件设置色值) - iOS

    为了便于日常开发效率,因此创建了一些小的工具类便于使用.具体 code 如下:声明: /* 为控件设置色值 */ #import <UIKit/UIKit.h> @interface UI ...

  2. iOS之用xib给控件设置圆角、边框效果

    xib中为各种控件设置圆角 通过代码的方式设置 @interface ViewController () @property (weak, nonatomic) IBOutlet UIView *my ...

  3. 我的QT5学习之路(三)——模板库、工具类和控件(下)

    一.前言 作为第三篇的最后一部分,我们来看一下Qt的控件,谈到控件,就会让人想到界面的美观性和易操作性,进而想到开发的便捷性.作为windows界面开发的MFC曾经是盛行了多少年,但是其弊端也随着其他 ...

  4. iOS之分别使用代码和storyboard、xib为控件设置圆角(以按钮为例)

    首先我们看一下代码是如何给按钮设置圆角的: 我们再来看看如何在storyboard或xib中给按钮设置圆角: 1.在storyboard或xib中添加按钮后,设置标题和背景色,做好约束: 2.点击 S ...

  5. Chapter2:Qt5模板库,工具类及控件

    2.1 字符串类 QString类保存16位Unicode值,提供了丰富的操作,查询和转换等函数.  (1):QString提供了一个二元的"+"操作符用于组合两个字符串  (2) ...

  6. iOS 在xib或storyboard里为控件添加圆角、外框和外框颜色

    如果要在xib和storyboard里为控件添加圆角和外框宽度,只要这样做就可以 layer.borderWidth     设置外框宽度属性 layer.cornerRadius    设置圆角属性 ...

  7. iOS在xib或storyboard里为控件添加圆角、外框和外框颜色

    如果要在xib和storyboard里为控件添加圆角和外框宽度,只要这样做就可以: layer.borderWidth 设置外框宽度属性 layer.cornerRadius 设置圆角属性 只要为属性 ...

  8. Xib中设置控件的圆角、边框效果

    设置控件的圆角和边框效果有两种方式: 1.代码实现: self.myView.layer.masksToBounds = YES; self.myView.layer.cornerRadius = ; ...

  9. 将控件画成圆角的效果(Delphi)

    最近在做一个Delphi的项目,常常要设计软件的界面,需要将控件画成圆角矩形.在Delphi中将控件画成圆角效果,可使用CreateRoundRectRgn函数.在此写了一个通用的函数,只要在用到改变 ...

随机推荐

  1. 跨域策略文件crossdomain.xml文件

    使用crossdomain.xml让Flash可以跨域传输数据 一.crossdomain.xml文件的作用    跨域,顾名思义就是需要的资源不在自己的域服务器上,需要访问其他域服务器.跨域策略文件 ...

  2. jstl标注标签库

    1.  常用标签 引入标签库: <%@ taglib prefix=”c” uri=”” %> 1.      C 标签   (1)<c:out value=”” default=” ...

  3. oracle学习篇五:组函数,分组统计

    常用组函数: 1.ccount() 求出全部记录数. 2.max() 求出一组最大值 3.min() 求出一组最小值 4.avg() 求出平均值 5.sum() 求和 --1.统计员工数量: sele ...

  4. mac上如何卸载node

    homebrew安装的 直接一条命令 brew uninstall node 官网下载pkg安装包的 一条命令 sudo rm -rf /usr/local/{bin/{node,npm},lib/n ...

  5. 1e6等于多少?

    如果抽象成这样:aeb 要求a不能不写,也就是说是1也要写上 b必须是整数. 实现上就是 a*10^b a乘以10的b次方 所以楼主的就是1*10^6 100000

  6. Stage2--Python的数据类型

    说在前面: Stage1-Stage4简单介绍一下Python语法,Stage5开始用python实现一些实际应用,语法的东西到处可以查看到,学习一门程序语言的最终目的是应用,而不是学习语法,语法本事 ...

  7. windows RT开发笔记:WinRT DLL及其调用研究

    一. 几个概念: WinRT : Windows Runtime, windows运行时.创建Windows运行时(WinRT)是为了在Windows上给用户提供一种流畅且安全的应用体验.WinRT会 ...

  8. python闭包&装饰器&偏函数

    什么是闭包? 首先还得从基本概念说起,什么是闭包呢?来看下维基上的解释: 在计算机科学中,闭包(Closure)是词法闭包(Lexical Closure)的简称,是引用了自由变量的函数.这个被引用的 ...

  9. supervisor运行virtualenv环境下的nagios-api

    supervisord-example.conf [unix_http_server] file=/tmp/supervisor.sock ; path to your socket file [su ...

  10. supersocket 通过配置文件启动服务 总是 初始化失败的 解决办法

    <serverTypes> <add name="APPServerType" type="TMPServer.APP.APPServer, TMPSe ...