UILabel Background Color Leaks to Border

前端 未结 6 1938
予麋鹿
予麋鹿 2021-02-19 03:48

I\'m creating a UILabel to which I set the background color and corner radius with the following code:

self.scoreLabel.backgroundColor = [UIColor DISRed];// cust         


        
6条回答
  •  花落未央
    2021-02-19 04:21

    I created my own UILabel and background colour does not seem to be leaking.

    1. Write this in .h file of your project.

      UILabel *label;

    2. Write this in .m file of your project.

    label=[[UILabel alloc]initWithFrame:CGRectMake(100, 300, 100, 100)];//Set frame of label in your viewcontroller.
        [label setBackgroundColor:[UIColor redColor]];//Set background color of label.
        [label setText:@"Label"];//Set text in label.
        [label setTextColor:[UIColor blackColor]];//Set text color in label.
        [label setTextAlignment:NSTextAlignmentCenter];//Set text alignment in label.
        [label.layer setCornerRadius:50.0];//Set corner radius of label to change the shape.
        [label.layer setBorderWidth:8.0f];//Set border width of label.
        [label setClipsToBounds:YES];//Set its to YES for Corner radius to work.
        [label.layer setBorderColor:[UIColor greenColor].CGColor];//Set Border color.
        [self.view addSubview:label];//Add it to the view of your choice.
    

提交回复
热议问题