我在检查器中看到我可以改变背景颜色,但是我想改变边框的颜色和粗细,可以吗?


当前回答

(self。view。layer setBorderColor: [uicolcolorwithred:0.265 green:0.447 blue:0.767 alpha:1.0f].CGColor];

其他回答

当我使用Vladimir的CALayer解决方案时,在视图的顶部我有一个动画,像一个模态UINavigationController解散,我看到很多故障发生,并有绘图性能问题。

另一种实现这个的方法,但是没有小故障和性能损失,是创建一个自定义UIView并实现drawRect消息,像这样:

- (void)drawRect:(CGRect)rect
{
    CGContextRef contextRef = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(contextRef, 1);
    CGContextSetRGBStrokeColor(contextRef, 255.0, 255.0, 255.0, 1.0);
    CGContextStrokeRect(contextRef, rect);    
}

你需要使用视图层来设置边界属性。例句:

#import <QuartzCore/QuartzCore.h>
...
view.layer.borderColor = [UIColor redColor].CGColor;
view.layer.borderWidth = 3.0f;

你还需要链接到QuartzCore.framework来访问这个功能。

view.layer.borderWidth = 1.0
view.layer.borderColor = UIColor.lightGray.cgColor

试试下面的代码:

view.layer.borderColor =  [UIColor redColor].CGColor;
view.layer.borderWidth= 2.0;
[view setClipsToBounds:YES];

swift 4.2中项目的边框颜色:

let cell = tableView.dequeueReusableCell(withIdentifier: "Cell_lastOrderId") as! Cell_lastOrder
cell.layer.borderWidth = 1
cell.layer.borderColor = UIColor.white.cgColor
cell.layer.cornerRadius = 10