Is there a way to animate changing a UILabel's textAlignment?

后端 未结 5 559
傲寒
傲寒 2020-12-06 11:25

I am using iOS 7 and I am trying to move a label that is centered off to the left of my view. Currently I am trying to do this by changing how my UILabel is aligned, and I a

5条回答
  •  粉色の甜心
    2020-12-06 11:54

    you can animate the FRAME, not the textAlignment.

    Do a [UILabel sizeToFit] on your label if you want to get rid of any "padding" on the frame, then you can animate the frame in your animation block to move it around as you desire

    CGRect frameLabel = self.monthLabel.frame;
    
    [UIView animateWithDuration:0.5
                     animations:^{
                          frameLabel.origin.x -= 100;          // e.g. move it left by 100
                          self.monthLabel.frame = frameLabel;
                     } completion:nil];
    

提交回复
热议问题