欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

IOS xib布局小技巧-边框设置

程序员文章站 2024-02-13 08:17:58
ios xib布局小技巧-边框设置 在xib或storyboard中为uiview添加边框或圆角 view的圆角半径(cornerradius)和边框宽度可以在右侧标识...

ios xib布局小技巧-边框设置

在xib或storyboard中为uiview添加边框或圆角

view的圆角半径(cornerradius)和边框宽度可以在右侧标识符检测器(第三个)上的user defined runtime attributes内进行设置,如图

IOS xib布局小技巧-边框设置

注:图中未设置圆角方法同上图边线宽度设置相同 key path : layer.cornerradius  value 处设置想要的半径即可

但是默认情况下边框的颜色是不能设置的,因为这里设置的颜色类型是uicolor而bordercolor是cgcolor因此显示不出来(个人观点,路过的大牛们要是觉得不对请指出,先谢过了),解决办法:为calayer写个类目添加个属性 uicolor *borderuicolor 利用setter方法设置bordercolor。

代码如下:


// 
// calayer+xibconfiguration.h 
//  
// 
// created by mls on 15/10/12. 
// copyright © 2015年 mls. all rights reserved. 
// 
 
#import <quartzcore/quartzcore.h> 
 
@interface calayer (xibconfiguration) 
 
// this assigns a cgcolor to bordercolor. 
@property(nonatomic, assign) uicolor *borderuicolor; 
 
@end 

// 
// calayer+xibconfiguration.m 
//  
// 
// created by mls on 15/10/12. 
// copyright © 2015年 mls. all rights reserved. 
// 
 
#import "calayer+xibconfiguration.h" 
 
@implementation calayer (xibconfiguration) 
 
-(void)setborderuicolor:(uicolor*)color 
{ 
  self.bordercolor = color.cgcolor; 
} 
 
-(uicolor*)borderuicolor 
{ 
  return [uicolor colorwithcgcolor:self.bordercolor]; 
} 
 
@end 



感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!