简体   繁体   English

在.xib的底部添加边框(objective-c)

[英]Add border to bottom of .xib (objective-c)

I am trying to only add a border to the bottom of my .xib view. 我试图仅在.xib视图的底部添加边框。 I currently have the following code which places a red border on ALL FOUR sides. 我目前有以下代码,该代码在所有四个面上都放置了红色边框。 I only want the border to be on ONE side, the bottom... How do I set the border to the bottom? 我只希望边框位于一侧,即底部...如何将边框设置为底部?

Current Code for class that controls .xib: 控制.xib的类的当前代码:

- (void)awakeFromNib {

    self.contentView.layer.borderWidth  = 5.0f;
    self.contentView.layer.masksToBounds = YES;
    self.contentView.layer.borderColor  = [UIColor redColor].CGColor;
}

This is what I get: 这是我得到的:
在此处输入图片说明

如果您不知道如何制作在底部绘制红色边框的视图,那么为什么不制作一个红色子视图并将其固定在底部呢?

  CALayer *bottomBorder = [CALayer layer];
  bottomBorder.borderColor = [UIColor redColor].CGColor;
  bottomBorder.borderWidth = 1;
  bottomBorder.frame       = CGRectMake(0, self.contentView.frame.size.height - bottomBorder.borderWidth, self.contentView.frame.size.width, bottomBorder.borderWidth);
  [self.contentView.layer addSublayer:bottomBorder];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM