Add just a top border to an UIView with Quartzcore/layer?

前端 未结 8 1527
天命终不由人
天命终不由人 2020-12-13 17:58

Is it possible to add a border just on top of a UIView, if so, how please?

8条回答
  •  遥遥无期
    2020-12-13 18:34

    i've find solution for me, here's the tricks :

    CGSize mainViewSize = self.view.bounds.size;
    CGFloat borderWidth = 1;
    UIColor *borderColor = [UIColor colorWithRed:37.0/255 green:38.0/255 blue:39.0/255 alpha:1.0];
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, mainViewSize.width, borderWidth)];
    topView.opaque = YES;
    topView.backgroundColor = borderColor;
    topView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;        
    [self.view addSubview:topView];
    

提交回复
热议问题