If not using an image?
_t.layer.shadowColor = [UIColor blackColor].CGColor;
_t.layer.shadowOffset = CGSizeMake(-6, -6);
_t.layer.shadowOpacity = 1;
_t.clipsToBounds = false;
this can create outside shadow.
Add view with shadow below status bar or tab bar, and these views are above your tableView.
CGFloat statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
CGFloat tabBarHeight = self.tabBarController.tabBar.bounds.size.height;
// status bar
UIView *statusBarShadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, statusBarHeight)];
statusBarShadowView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:statusBarShadowView];
CAGradientLayer *gradientLayer0 = [CAGradientLayer layer];
gradientLayer0.frame = CGRectMake(0, statusBarHeight, self.view.bounds.size.width, 10);
gradientLayer0.colors = #[(id)[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.7].CGColor, (id)[UIColor colorWithWhite:1 alpha:0.7].CGColor];
[statusBarShadowView.layer insertSublayer:gradientLayer0 atIndex:0];
// tab bar
UIView *tabBarShadowView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - tabBarHeight, [UIScreen mainScreen].bounds.size.width, tabBarHeight)];
statusBarShadowView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:tabBarShadowView];
CAGradientLayer *gradientLayer1 = [CAGradientLayer layer];
gradientLayer1.frame = CGRectMake(0, -10, self.view.bounds.size.width, 10);
gradientLayer1.colors = #[(id)[UIColor colorWithWhite:1 alpha:0.7].CGColor, (id)[UIColor colorWithRed:0.91 green:0.91 blue:0.91 alpha:0.7].CGColor];
[tabBarShadowView.layer insertSublayer:gradientLayer1 atIndex:0];
Related
I need to create some UIView in circular shape and showing text below that. I have created circle successfully. But is there any way that I should add label below that circle. I need to display many circle with text. Below is my code of circle and attach is the screen shot which I need to create.
- (UIView*)createCircleViewWithRadius
{
// circle view
UIView *circle = [[UIView alloc] initWithFrame:CGRectZero];
circle.translatesAutoresizingMaskIntoConstraints = NO;
circle.layer.cornerRadius = 50;
circle.layer.masksToBounds = YES;
// border
circle.layer.borderColor = [UIColor lightGrayColor].CGColor;
circle.layer.borderWidth = 1;
// gradient background color
CAGradientLayer *gradientBg = [CAGradientLayer layer];
gradientBg.frame = circle.frame;
gradientBg.colors = [NSArray arrayWithObjects:
(id)[UIColor clearColor].CGColor,
(id)[UIColor clearColor].CGColor,
nil];
// vertical gradient
gradientBg.locations = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:1.0f],
nil];
// gradient background
CALayer *layer = circle.layer;
layer.masksToBounds = YES;
[layer insertSublayer:gradientBg atIndex:0];
return circle;
}
do like
UILabel *yourItemlabel = [[UILabel alloc]initWithFrame:CGRectMake(yourView.frame.origin.x + 10, yourView.frame.origin.y + yourView.frame.size.height + 10 , yourView.frame.size.width, 30)]; // customize the height
yourItemlabel.text = #"Request funds";
yourItemlabel.textAlignment = NSTextAlignmentCenter;
[sel.view addSubview:yourItemlabel];
You can do something like,
UIView *containerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 170, 200)];
UIView *circle = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 150, 150)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 170, 150, 30)];
label.text = #"Request funds";
label.textAlignment = NSTextAlignmentCenter;
circle.layer.borderColor = [UIColor lightGrayColor].CGColor;
circle.layer.borderWidth = 1.0;
circle.layer.cornerRadius = 75; // width or height / 2 and width = height (must for proper round shape)
circle.layer.masksToBounds = YES;
[containerView addSubview:circle];
[containerView addSubview:label];
[self.view addSubview: containerView];
You can modify size and origins according your need. this is demonstration that how you can achieve this.
Hope this helps!
I want to animate content of scrollview i have tried this for animation.
- (void)viewDidLoad {
[super viewDidLoad];
//Scroll View Created Programmatically
scrollview=[[UIScrollView alloc] initWithFrame:self.view.bounds];
scrollview.delegate=self;
scrollview.contentSize=CGSizeMake(scrollview.bounds.size.width, self.view.bounds.size.height);
[self.view addSubview:scrollview];
// Road Image Created Programmatically
backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
backgroundImageView.image = [UIImage imageNamed:#"roadds.png"];
backgroundImageView.contentMode = UIViewContentModeRedraw;
[scrollview addSubview:backgroundImageView];
// Tree top left Created Programmatically
Tree = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 30, 50)];
Tree.image = [UIImage imageNamed:#"rsz_1rsz_tree.png"];
Tree.contentMode = UIViewContentModeTopLeft;
[scrollview addSubview:Tree];
//Tree top Right
Tree1 = [[UIImageView alloc] initWithFrame: CGRectMake(self.view.frame.size.width-30, 0, 30, 50)];
Tree1.image = [UIImage imageNamed:#"rsz_tree1.png"];
Tree1.contentMode = UIViewContentModeTopRight;
[scrollview addSubview:Tree1];
//Tree Bottom left
Tree2 = [[UIImageView alloc] initWithFrame: CGRectMake(0, self.view.frame.size.height-80, 30, 50)];
Tree2.image = [UIImage imageNamed:#"rsz_tree2.png"];
Tree2.contentMode = UIViewContentModeBottomLeft;
[scrollview addSubview:Tree2];
//Tree Bottom Right
Tree3 = [[UIImageView alloc] initWithFrame: CGRectMake(self.view.frame.size.width-30, self.view.frame.size.height-80, 30, 50)];
Tree3.image = [UIImage imageNamed:#"rsz_tree3.png"];
Tree3.contentMode = UIViewContentModeBottomRight;
[scrollview addSubview:Tree3];
// Car
car = [[UIImageView alloc] initWithFrame: CGRectMake((self.view.frame.size.width)/2+20, self.view.frame.size.height-120, 40, 60)];
car.image = [UIImage imageNamed:#"rsz_car1.png"];
car.contentMode = UIViewContentModeCenter;
[scrollview addSubview:car];
//Grass
grass = [[UIImageView alloc] initWithFrame:CGRectMake(0, (self.view.frame.size.height)/2,30, 30)];
grass.image = [UIImage imageNamed:#"rsz_grass.png"];
grass.contentMode = UIViewContentModeBottomLeft;
[scrollview addSubview:grass];
//Grass
grass1 = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width-60, (self.view.frame.size.height)/2,30, 30)];
grass1.image = [UIImage imageNamed:#"rsz_grass1.png"];
grass1.contentMode = UIViewContentModeBottomLeft;
[scrollview addSubview:grass1];
// Left Arrow
left = [[UIButton alloc] initWithFrame:CGRectMake((self.view.frame.size.width)/2+60, (self.view.frame.size.height-35),30, 30)];
[left setBackgroundImage:[UIImage imageNamed:#"rsz_arrowl.png"]forState:UIControlStateNormal];
left.contentMode = UIViewContentModeBottomRight;
[scrollview addSubview:left];
//right arrow
right = [[UIButton alloc] initWithFrame:CGRectMake((self.view.bounds.size.width)/2 - 90, (self.view.frame.size.height-35),30, 30)];
[right setBackgroundImage:[UIImage imageNamed:#"rsz_arrowr.png"]forState:UIControlStateNormal];
right.contentMode = UIViewContentModeBottomLeft;
[scrollview addSubview:right];
// For Animation
CGRect bounds = scrollview.bounds;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"bounds"];
animation.duration = 10;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fromValue = [NSValue valueWithCGRect:bounds];
bounds.origin.y += 100;
animation.toValue =[NSValue valueWithCGRect:bounds];
[scrollview.layer addAnimation:animation forKey:#"bounds"];
scrollview.bounds = bounds;
}
Add UIView to ScrollView and then add your all stuff to this view.
And add animation to this view or view's layer. Hope this will work. :)
If you want your initial position back after animation add this line
bounds.origin.y -= 100;
after
[scrollview.layer addAnimation:animation forKey:#"bounds"];
so, last five line of your viewdidLoad should as below,
bounds.origin.y += 100;
animation.toValue =[NSValue valueWithCGRect:bounds];
[scrollview.layer addAnimation:animation forKey:#"bounds"];
bounds.origin.y -= 100;
scrollview.bounds = bounds;
I am trying to put transparency (or a color gradient) on the title of an UIButton. I don't know how do that. I have tried to simply put a clearColor on the titleColor but we only see the background color.
So i hope that there is someone here who will be an amazing idea for my problem.
My solution
self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.loginButton.backgroundColor= [UIColor whiteColor];
self.loginButton.frame = CGRectMake(self.signUpButton.left,
0,
self.signUpButton.frame.size.width,
self.signUpButton.frame.size.height);
[self.loginButton.layer setBackgroundColor:[[UIColor blackColor] CGColor]];
self.loginButton.layer.borderColor = [[UIColor whiteColor] CGColor];
self.loginButton.layer.borderWidth = 1.0f;
self.loginButton.layer.cornerRadius = 3.0f;
[self.loginButton addTarget:self action:#selector(loginButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.loginButtonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
self.loginButtonLabel.font = [UIFont fontWithName:#"OpenSans-Light" size:16.0f];
self.loginButtonLabel.textColor = [UIColor whiteColor];
self.loginButtonLabel.text = #"Connexion";
[self.loginButtonLabel sizeToFit];
UIColor *topColor = [UIColor blueColor];
UIColor *bottomColor = [UIColor orangeColor];
self.gradientView = [[UIView alloc] initWithFrame:self.loginButtonLabel.frame];
[self.loginButton addSubview:self.gradientView];
[self.loginButton sendSubviewToBack:self.gradientView];
[self.loginButton addSubview:self.loginButtonLabel];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.gradientView.frame;
gradient.colors = [NSArray arrayWithObjects:(id)topColor.CGColor, (id)bottomColor.CGColor, nil];
gradient.startPoint = CGPointMake(0, 0.5);
gradient.endPoint = CGPointMake(1, 0.5);
[self.gradientView.layer addSublayer:gradient];
self.gradientView.layer.mask = self.loginButtonLabel.layer;
self.gradientView.layer.masksToBounds = YES;
self.gradientView.center = CGPointMake(self.loginButton.width / 2, self.loginButton.height / 2);
[self.view addSubview:self.loginButton];
But Now i need to put the gradient on the border. Any idea ?
So my solution is to create a custom button with an UILabel. I will use an UIView with a gradient for color the text.
The solution :
self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.loginButton.backgroundColor= [UIColor whiteColor];
self.loginButton.frame = CGRectMake(self.signUpButton.left,
0,
self.signUpButton.frame.size.width,
self.signUpButton.frame.size.height);
[self.loginButton.layer setBackgroundColor:[[UIColor blackColor] CGColor]];
self.loginButton.layer.borderColor = [[UIColor whiteColor] CGColor];
self.loginButton.layer.borderWidth = 1.0f;
self.loginButton.layer.cornerRadius = 3.0f;
[self.loginButton addTarget:self action:#selector(loginButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.loginButtonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
self.loginButtonLabel.font = [UIFont fontWithName:#"OpenSans-Light" size:16.0f];
self.loginButtonLabel.textColor = [UIColor whiteColor];
self.loginButtonLabel.text = #"Connexion";
[self.loginButtonLabel sizeToFit];
UIColor *topColor = [UIColor blueColor];
UIColor *bottomColor = [UIColor orangeColor];
self.gradientView = [[UIView alloc] initWithFrame:self.loginButtonLabel.frame];
[self.loginButton addSubview:self.gradientView];
[self.loginButton sendSubviewToBack:self.gradientView];
[self.loginButton addSubview:self.loginButtonLabel];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.gradientView.frame;
gradient.colors = [NSArray arrayWithObjects:(id)topColor.CGColor, (id)bottomColor.CGColor, nil];
gradient.startPoint = CGPointMake(0, 0.5);
gradient.endPoint = CGPointMake(1, 0.5);
[self.gradientView.layer addSublayer:gradient];
self.gradientView.layer.mask = self.loginButtonLabel.layer;
self.gradientView.layer.masksToBounds = YES;
self.gradientView.center = CGPointMake(self.loginButton.width / 2, self.loginButton.height / 2);
[self.view addSubview:self.loginButton];
I have a UIView and two subviews in it. The subviews have rounded corners and a border value. The issue I have is that the outer edges of the rounded border contain a thin line of the subview background color. I must be missing something??
UIView *outerView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 320, 320)];
[self.view addSubview:outerView];
outerView.backgroundColor = [UIColor whiteColor];
UIView *innerView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 160, 320)];
[outerView addSubview:innerView1];
innerView1.backgroundColor = [UIColor blackColor];
innerView1.layer.borderWidth = 20;
innerView1.layer.borderColor = [UIColor whiteColor].CGColor;
innerView1.layer.cornerRadius = 20;
//innerView1.layer.masksToBounds = YES;
UIView *innerView2 = [[UIView alloc] initWithFrame:CGRectMake(160, 0, 160, 320)];
[outerView addSubview:innerView2];
innerView2.backgroundColor = [UIColor blackColor];
innerView2.layer.borderWidth = 20;
innerView2.layer.borderColor = [UIColor whiteColor].CGColor;
innerView2.layer.cornerRadius = 20;
//innerView2.layer.masksToBounds = NO;
//innerView2.clipsToBounds = YES;
//innerView2.layer.shouldRasterize = YES;
To work around the problem, set the background color of the subviews to clearColor and then draw the background color using the drawRect method of a custom view class. Here's the code for the view class.
#interface WorkAroundView : UIView
#end
#implementation WorkAroundView
- (void)drawRect:(CGRect)rect
{
CGFloat margin = self.layer.borderWidth;
CGRect background;
background.origin.x = margin;
background.origin.y = margin;
background.size.width = self.bounds.size.width - 2 * margin;
background.size.height = self.bounds.size.height - 2 * margin;
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect( context, background );
}
#end
And here's how you would use the custom view class. The only real change here from what you posted is that the background color for the subviews is set to clearColor.
UIView *outerView = [[UIView alloc] initWithFrame:CGRectMake(360, 200, 320, 320)];
[self.view addSubview:outerView];
outerView.backgroundColor = [UIColor whiteColor];
WorkAroundView *innerView1 = [[WorkAroundView alloc] initWithFrame:CGRectMake(0, 0, 160, 320)];
innerView1.backgroundColor = [UIColor clearColor];
innerView1.layer.borderWidth = 20;
innerView1.layer.borderColor = [UIColor whiteColor].CGColor;
innerView1.layer.cornerRadius = 20;
[outerView addSubview:innerView1];
WorkAroundView *innerView2 = [[WorkAroundView alloc] initWithFrame:CGRectMake(160, 0, 160, 320)];
innerView2.backgroundColor = [UIColor clearColor];
innerView2.layer.borderWidth = 20;
innerView2.layer.borderColor = [UIColor whiteColor].CGColor;
innerView2.layer.cornerRadius = 20;
[outerView addSubview:innerView2];
add a bezier path around the corner
CAShapeLayer *subLayer = [[CAShapeLayer alloc] init];
[subLayer setFillColor:[UIColor clearColor].CGColor];
[subLayer setStrokeColor:[UIColor whiteColor].CGColor];
[subLayer setLineWidth:1.0];
[subLayer setPath:[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:imageView.layer.cornerRadius].CGPath];
[imageView.layer addSublayer:subLayer];
I am trying to add a gradient behind a transparent image. I do this on the map leftCallOutAccessoryView however no matter what I try the gradient layer always shows above the imageView and want it to appear behind it
heres my code for MKAnnotationView which is an ivar called pinView
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Profile.png"]];
pinView.leftCalloutAccessoryView = profileIconView;
CAGradientLayer *backgroundLayer = [CAGradientLayer layer];
backgroundLayer.frame = CGRectMake(0, 0, 30, 30);
backgroundLayer.cornerRadius = 2;
backgroundLayer.borderWidth = 1;
backgroundLayer.borderColor = [UIColor whiteColor].CGColor;
backgroundLayer.colors = [NSArray arrayWithObjects:(id)[[sharedManager cellGradientEnd] CGColor], (id)[[sharedManager cellGradientStart] CGColor], nil];
[profileIconView.layer insertSublayer:backgroundLayer atIndex:0];
I managed to figure it out using the below, in short I create a empty view then add the imageView as a subview to the view and now its all sweet!:
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Profile.png"]];
pinView.leftCalloutAccessoryView = view;
CAGradientLayer *backgroundLayer = [CAGradientLayer layer];
backgroundLayer.frame = view.bounds;
backgroundLayer.cornerRadius = 2;
backgroundLayer.borderWidth = 1;
backgroundLayer.borderColor = [UIColor whiteColor].CGColor;
backgroundLayer.colors = [NSArray arrayWithObjects:(id)[[sharedManager cellGradientEnd] CGColor], (id)[[sharedManager cellGradientStart] CGColor], nil];
[pinView.leftCalloutAccessoryView.layer insertSublayer:backgroundLayer atIndex:0];
[view addSubview:profileIconView];