user1926201
user1926201

Reputation: 113

UIView with glass effect

I want to create a view which should have a glass like effect. It should look shining as well. On that i want to add a UITextView which should appear transparent. I'm new to IPhone and not getting how to do this. I don't want to add image. Wanna do programmatically. The view should look like as if it is a mobile screen.

Thanks

Upvotes: 3

Views: 1622

Answers (1)

Rushi
Rushi

Reputation: 4500

You'll have to do things if you don't want to use the image.

  1. Add one UIView Use this code. And set gradient background color to it. Which will give you shiny glass like effect.

Here is the code:

.h file :

UIColor                                         *pinkDarkOp;
UIColor                                         *pinkLightOp;
CAGradientLayer                                 *gradient;

.m file :

img_TopBarView = [[UIView alloc]initWithFrame:CGRectMake(0.0,0.0,1024.0,50.0)];
img_TopBarView.userInteractionEnabled = YES;
pinkDarkOp = [UIColor colorWithRed:15.0f/255.0 green:138.0f/255.0 blue:216.0f/255.0 alpha:1.0];
pinkLightOp = [UIColor colorWithRed:12.0f/255.0 green:91.0f/255.0 blue:183.0f/255.0 alpha:1.0];
gradient = [CAGradientLayer layer];
gradient.frame = [[img_TopBarView layer] bounds];
gradient.colors = [NSArray arrayWithObjects:(id)pinkDarkOp.CGColor,(id)pinkLightOp.CGColor,nil];
gradient.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],[NSNumber numberWithFloat:0.7],nil];
[[img_TopBarView layer] insertSublayer:gradient atIndex:0];
[self.view addSubview:img_TopBarView];
[img_TopBarView release];

You have to take the values of pinkDarkOp and pinkLightOp as per your need. You can get this color code anywhere on google.

For eg : http://gradients.glrzad.com

  1. For Creating the transparent UITextView you can use the alpha property of the UITextView.

I hope this helps.

Upvotes: 1

Related Questions