如何在iOS的UiView中添加顶部或底部边框?

时间:2019-02-12 10:18:04

标签: ios swift uiview

enter image description here

上面的边框是我想要实现的。

1 个答案:

答案 0 :(得分:2)

尝试

-(void)addBottomBorderToView:(UIView *)view{
    UIView *bottomBorder = [[UIView alloc]initWithFrame:CGRectMake(0,view.frame.size.height - 1, view.frame.size.width, 1)];
    bottomBorder.backgroundColor = UIColor.darkGrayColor;
    [view addSubview:bottomBorder];
}

迅速:

func addBottomView(view : UIView){
    let bottomView = CGRect(0,view.frame.size.height-1,view.frame.size.width,1)
    bottomView.backgroundColor = UIColor.darkGrayColor
    view.addSubView(bottomView)
}