iOS - trying to rotate a text label and the label disappears

后端 未结 2 1239
予麋鹿
予麋鹿 2021-01-28 13:15

I\'m trying to rotate a label on my view 90 degrees. I\'ve tried the two following ways to do it and the label just disappears from the screen. I triple checked that the prope

2条回答
  •  北海茫月
    2021-01-28 13:38

    I am not 100% sure if it works or not but why are you not using M_PI_2. It's just simple thought that you are assuming Value of Pi to be 3.14 but the exact value is 3.14159...

    I did it like this and it worked fine :

    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 50, 70)];
    lbl.text = @"New";
    lbl.backgroundColor = [UIColor clearColor];
    lbl.textColor = [UIColor whiteColor];
    lbl.highlightedTextColor = [UIColor blackColor];
    lbl.font = [UIFont systemFontOfSize:12];
    lbl.transform = CGAffineTransformMakeRotation(M_PI_2);
    [self.view addSubview:lbl];
    

    You can also check Answers from these Questions :

    How to Render a rotated UIlabel

    Rotating UILabel at its center

    Hope it will be helpful for you.

提交回复
热议问题