-
2014-07-23 11:32:51
- (void)setViewLayer{ //边框 View.layer.borderColor = [UIColor colorWithRed:205/255.0 green:211/255.0 blue:213/255.0 alpha:1.0].CGColor;//#cdd3d5 View.layer.borderWidth = 1.0f; // 设置登录按钮圆角半径 View.layer.masksToBounds = YES; View.layer.cornerRadius = 2; }
更多相关内容 -
iOS应用开发中UIView添加边框颜色及设置圆角边框的方法
2021-01-04 01:40:19UIView加边框及边框颜色 引用库: 代码如下: #import 使用: 代码如下: //添加边框和提示 CGRect frameRect = CGRectMake(20, 90, self.window.frame.size.width-40, self.window.frame.size.height-180); ... -
xib如何给UIView设置圆角,为何xib设置UIView边框颜色不显示
2018-12-21 17:51:29xib为何设置UIView圆角不显示: 首先上图:  xib设置圆角只需要按照图中步骤添加对应Key Path 最常用的Key Path: layer.cornerRadius ,注意该 key 对应 Value 的 type 应该设置为 String/Number 两种...最近用xib创建view,遇到一些问题,记录下,希望可以帮到遇到同样问题的童鞋:
xib为何设置UIView圆角不显示:
首先上图:
xib设置圆角只需要按照图中步骤添加对应Key Path
最常用的Key Path:- layer.cornerRadius ,注意该 key 对应 Value 的 type 应该设置为 String/Number
两种类型均可(代码设置弧度为:thisViewlayer.masksToBounds = YES) - layer.masksToBounds ,注意该 key 对应 Value 的 type 应该设置为 Boolean ,
当右侧出现对号时为YES(代码圆角为:thisView.layer.masksToBounds = YES) - layer.borderWidth ,注意该 key 对应 Value 的 type 应该设置为 String/Number
两种类型均可(代码设置边框宽度为:thisViewlayer.borderWidth = 2) - layer.borderColor , 注意该 key 对应 Value 的 type 应该设置为
Color(代码设置边框颜色:thisView.layer.borderColor = [UIColor
redColor].CGColor)
最大的坑:
如果你从上面一直敲下来的话,你会发现只有1和2的两句代码是有效的;3,4两句代码看起来并没有效果原因:其实是因为在设置borderColor的时候,需要接受的是一个CGColor,而在 key Path中只有Color,其实就是 UIColor,类型是不对的,因此并没有正确显示想要展现的颜色.
平时代码中设置layer的颜色是这样的
self.customView.layer.borderColor = [UIColor blackColor].CGColor; //而不是 self.customView.layer.borderColor = [UIColor blackColor]; //所以可以看出,layer 的borderColor接受的CGColor 而不是普通法人UIColor,代码中有区分,那么xib中肯定也必须给CGColor而不是UIColor
因此这样的写法是有问题的,需要在代码中引入一个CALayer的分类:(可以参照下面创建分类,也可以自行百度搜索此分类~~)通过添加一个CALayer的类扩展,将key Path中设置的UIColor转换成为CGColor,xib为边框设置颜色时的Key Path就是上图中的layer.borderColorFromUIColor然后xcode run起来就可以正确看到边框啦,只是在xib文件中好像仍然看不到效果?
CALayer的分类分类实现如下:#import <QuartzCore/QuartzCore.h> @interface CALayer (LayerColor) - (void)setBorderColorFromUIColor:(UIColor *)color; @end
#import "CALayer+LayerColor.h" #import <UIKit/UIKit.h> @implementation CALayer (LayerColor) - (void)setBorderColorFromUIColor:(UIColor *)color{ self.borderColor = color.CGColor; } @end
- layer.cornerRadius ,注意该 key 对应 Value 的 type 应该设置为 String/Number
-
IOS开发入门之UIView添加边框颜色及设置圆角边框的方法
2021-01-17 11:23:37本文将带你了解IOS开发入门iOS应用开发中UIView添加边框颜色及设置圆角边框的方法,希望本文对大家学IOS有所帮助。UIView加边框及边框颜色引用库:复制代码代码如下:#import使用:复制代码代码如下://添加边框和提示...本文将带你了解IOS开发入门iOS应用开发中UIView添加边框颜色及设置圆角边框的方法,希望本文对大家学IOS有所帮助。
UIView加边框及边框颜色
引用库:
复制代码 代码如下:
#import
使用:
复制代码 代码如下:
//添加边框和提示
CGRect frameRect = CGRectMake(20, 90, self.window.frame.size.width-40, self.window.frame.size.height-180);
UIView *frameView = [[UIView alloc] initWithFrame:frameRect] ;
frameView.layer.borderWidth = 1;
frameView.layer.borderColor = [[UIColor whiteColor] CGColor];
设置UIView的边框为圆角
在实际的应用中,总感觉圆角的东西比较好看, 像button,label,image等等,以前的时候我就经常给那些控件添加一个UIImageView作为背景,再搞张圆角的图片,不过今天发现了新方法看代码
复制代码 代码如下:
viewT.layer.cornerRadius = 10;//设置那个圆角的有多圆
viewT.layer.borderWidth = 10;//设置边框的宽度,当然可以不要
viewT.layer.borderColor = [[UIColor redColor] CGColor];//设置边框的颜色
viewT.layer.masksToBounds = YES;//设为NO去试试
其实的viewT是UIView的实例,当然也可以是他的子类实例哈。
最后别忘记添加QuartzCore.framework这个库,还有在你的文件中包含#import 这句哦
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之IOS频道!
-
iOS(swift)UIView设置边框,切圆角
2020-11-06 20:00:53view.layer.cornerRadius = 3 view.layer.borderColor = UIColor.gray.cgColor view.layer.borderWidth = 1 参考博客: iOS 如何给UIView 添加边框view.layer.cornerRadius = 3 view.layer.borderColor = UIColor.gray.cgColor view.layer.borderWidth = 1
参考博客:
iOS 如何给UIView 添加边框 -
UIView加边框及颜色
2016-12-02 14:14:00UIView *view = [[UIView alloc] init]; view.layer.borderWidth = 1; view.layer.borderColor = [[UIColor redColor] CGColor]; -
【iOS开发】自定义UIView边框的颜色
2016-05-30 11:42:21开发中经常要修改UIView某一个边框的颜色,特别是UITableView。核心代码如下:- (void)setBorderWithView:(UIView *)view top:(BOOL)top left:(BOOL)left bottom:(BOOL)bottom right:(BOOL)right borderColor:... -
UIView/UIButton任意添加某个边框
2017-10-31 15:03:17通过该类可以任意为UIView/UIButton等控件添加某条边的边框,包括边框大小和颜色 -
iOS 给UIView添加虚线边框
2022-03-08 10:36:26extension UIView{ /* width:虚线的宽度 length:虚线的长度 space:虚线间的间距 cornerRadius:view圆角 color:虚线的颜色 */ func swiftDrawBoardDottedLine(width:CGFloat, length:CGFloat,space:... -
BorderedView:一个 UIView 子类(在 Swift 中),具有可在界面生成器上配置的角半径、边框宽度和边框颜色
2021-06-05 08:53:20一个 UIView 子类(在 Swift 中),具有可在 Interface Builder 上配置的角半径、边框宽度和边框颜色。 用法 要运行示例项目, pod install克隆 repo,然后从 Example 目录运行pod install 。 要求 安装 ... -
UIView加边框及边框颜色
2014-03-22 19:35:03UIView加边框及边框颜色 -
oc和swift UIView类扩展画虚线外边框
2020-12-08 17:20:03封装了oc和 swift的 2个UIView的虚线外框的类扩展,可以设置线的长度,间隙长度,虚线宽度,虚线颜色,外框圆角边框,一行代码调用非常方便 -
IOS的layer的实现UIView的边框、颜色、半径
2015-05-01 13:47:41//创建一个UIView UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; //设置view的背景色 view.backgroundColor = [UIColor orangeColor]; //把UIView添加到父控件Vie -
设置UIView阴影shadow 边框 边框颜色
2019-09-28 04:33:44http://www.cnblogs.com/worldworld/archive/2012/05/23/2515146.html 转载于:https://www.cnblogs.com/Ruby_c/p/5909151.html -
iOS 设置UIView的边框和阴影
2014-09-20 10:57:31设置UIView的边框和阴影其实很简单,UIView -
iOS-UIView加边框以及边框颜色
2016-11-01 19:50:29iOS-UIView加边框以及边框颜色UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200,200 )]; //边框宽 bgView.layer.borderWidth = 1; //边框颜色 bgView.layer.borderColor = [[UIColor ... -
iOS之UIView加边框及边框颜色
2016-02-05 12:27:43引用库: #import 使用: //添加边框和提示 CGRect frameRect = CGRectMake(20, 90, self.window.frame.size.width-40, self.window.frame.size...UIView *frameView = [[UIView alloc] initWithFrame:frameRect] ; f -
UIView设置边框(整体设置和分开设置)
2017-06-28 20:09:37在开发中为UIView设置边框是常常用到的功能,如果要为UIView四下都设置边框,最简单的方法是使用CALayer的border属性: +(void)setViewBorder:(UIView *)view color:(UIColor *)color radius:(float)radius border:... -
UIView 设置边框颜色 和 UILabel 的设置
2015-10-25 15:47:002019独角兽企业重金招聘Python工程师标准>>> ... -
为uiview设置单边边框
2018-04-28 16:32:30原生的 UIKit 并没有提供设置单边边框(border)的功能,view.layer.borderColor和view.layer.borderWidth 会把上下左右的边框一起设置。所以想设置单边只能自己来实现了。画border线的思路很简单,其实就是画一条... -
UIButton,UIView添加渐变边框
2021-06-03 14:36:26思路参考举例UIButtom思路:1、 首先创建一个临时的 UIView2、 然后利用 CAGradientLayer 在 UIView 上面进行渐变绘制3、将UIView 进行截图返回 UIImage4、将返回的 UIImage 设置到 UIButton 的 setBackgroundImage... -
IOS自定义UIView
2020-08-31 04:39:10本文主要介绍下存代码的自定义UIView和能够在storeboard中实时显示效果的自定义UIView。下面跟着小编一起来看下吧 -
UIView边框设置
2013-09-23 16:31:35- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor whiteColor];... * viewTest=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)]; view