简体   繁体   中英

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

I am trying to only add a border to the bottom of my .xib view. 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:

- (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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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