设置只为View加一条边框,子视图大小超出父视图大小,边框在子视图下边显示

#import "ViewController.h"

 

@interface ViewController ()

@property (strong,nonatomic) UIView *Fview;

@property (strong,nonatomic) UIView *Zview;

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    _Fview = [[UIView alloc]initWithFrame:CGRectMake(120,200, 100, 100)];

    _Fview.backgroundColor = [UIColor greenColor];

    [self.view addSubview:_Fview];

    

    CALayer *blayer = [[CALayer alloc]init];

    blayer.frame =CGRectMake(0, 0, 100, 1);

    blayer.backgroundColor = [UIColor blackColor].CGColor;

    [_Fview.layer addSublayer:blayer];

    

    _Zview = [[UIView alloc]initWithFrame:CGRectMake(20,-10, 100, 120)];

    _Zview.backgroundColor = [UIColor redColor];

    [_Fview addSubview:_Zview];

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

原文地址:https://www.cnblogs.com/Mrliheng/p/5434036.html