0

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.enter image description here

- (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;
}
Kashif Jilani
  • 1,207
  • 3
  • 22
  • 49
  • Please visit this link, answer to your question is already there: http://stackoverflow.com/questions/10051514/how-can-i-insert-a-subview-below-the-other-subviews – Aamir Jul 27 '16 at 06:56

2 Answers2

0

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!

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
0

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];
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • -(UILabel *)createViewLabel:(UIView *)view text:(NSString *)labelText { UILabel *labelCon = [UILabel new]; labelCon.frame = CGRectMake(view.frame.origin.x-15, view.frame.origin.y + view.frame.size.height , view.frame.size.width+30, 35); labelCon.text = labelText; labelCon.numberOfLines = 0; labelCon.backgroundColor = [UIColor clearColor]; labelCon.font = [UIFont fontWithName:@"Roboto-Regular" size:12]; labelCon.textColor = [UIColor darkGrayColor]; labelCon.textAlignment = NSTextAlignmentCenter; return labelCon; } – Kashif Jilani Jul 28 '16 at 06:29