Evgeniy Kleban Evgeniy Kleban -5 years ago 239
iOS Question

Make part of UIView visible

I want to add a "shadow" image on my view, but, i want part of my view to still be "visible". You better understand what i want to do, when look on screenshot:enter image description here

I can add a

above my superview, but how could i make specific point "visible"? That actually mean make specific area of a view with different colour or opaque.

Answer Source

For your problem i had a way..Try the below example..

1. First storyboard design: i had a UIButton

enter image description here

2. Added black View as a subview

    UIView *blackView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    blackView.backgroundColor=[UIColor blackColor];
    [self.view addSubview:blackView];

now result will be:

enter image description here

3. Add one more UIImageView with frame equal to button frame

  UIImageView *imageView=[[UIImageView alloc]init];
  imageView.frame=self.button.frame; //getting current UIButton bounds
  imageView.image=[UIImage imageNamed:@"add_img.png"];
  [self.view addSubview:imageView];

Now it looks same as what u want:

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download