How to create a UIView transparency with a non-transparent border


I am trying to make a transparent UIView with a border. The problem is that the border will always be transparent, how can I make it non-transparent?

This is my code

- (void) viewDidLoad:(BOOL)animated

  [super viewDidLoad:animated]; 

  _transparentView.alpha = 0.5f;
  _transparentView.layer.borderColor = [UIColor whiteColor].CGColor;
  _transparentView.layer.borderWidth = 2.0f;

You can do it by adding transparent view to as a sub-view of another view like as bellow

_transparentView.alpha = 0.5f;

_MainView.backgroundColor = [UIColor clearColor];
_MainView.layer.borderColor = [UIColor whiteColor].CGColor;
_MainView.layer.borderWidth = 2.0f;
[_MainView addSubview:_transparentView];