iOS UIKit:UILabel

1、创建一个UILabel:

UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(10, 100, 300, 180)];

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 150)];

label.text = @"Hello world! Hello world!Hello world! Hello world! Hello world! Hello world! Hello world! Hello world!Hello world! Hello world! Hello world! Hello world! Hello world! Helloworld!";

// 背景颜色为红色

label.backgroundColor = [UIColor redColor];

// 设置字体颜色为白色

label.textColor = [UIColor whiteColor];

// 文字居中显示

label.textAlignment = UITextAlignmentCenter;

// 自动折行设置

label.lineBreakMode = UILineBreakModeWordWrap;

label.numberOfLines = 0;
label.transform = CGAffineTransformMakeRotation(0.1);     //设置label的旋转角度
label.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];   //设置label的字体和字体大小。
 label.shadowColor = [UIColorcolorWithWhite:0.1falpha:0.8f];    //设置文本的阴影色彩和透明度。

 2、THLabelTHLabel是UILabel的子类, 支持阴影模糊、笔画文本以及渐变填充。

// Demonstrate shadow blur.

    [self.label1 setShadowColor:[UIColor blackColor]];

    [self.label1 setShadowOffset:CGSizeMake(0.0f, kShadowOffsetY)];

    [self.label1 setShadowBlur:kShadowBlur];

    

    // Demonstrate stroke.

    [self.label2 setStrokeColor:[UIColor blackColor]];

    [self.label2 setStrokeSize:kStrokeSize];

    

    // Demonstrate fill gradient.

    [self.label3 setGradientStartColor:[UIColor colorWithRed:255.0f / 255.0f green:193.0f / 255.0f blue:127.0f / 255.0f alpha:1.0f]];

    [self.label3 setGradientEndColor:[UIColor colorWithRed:255.0f / 255.0f green:163.0f / 255.0f blue:64.0f / 255.0f alpha:1.0f]];

    

    // Demonstrate everything.

    [self.label4 setShadowColor:[UIColor colorWithWhite:0.0f alpha:0.75f]];

    [self.label4 setShadowOffset:CGSizeMake(0.0f, kShadowOffsetY)];

    [self.label4 setShadowBlur:kShadowBlur];

    [self.label4 setStrokeColor:[UIColor blackColor]];

    [self.label4 setStrokeSize:kStrokeSize];

    [self.label4 setGradientStartColor:[UIColor colorWithRed:255.0f / 255.0f green:193.0f / 255.0f blue:127.0f / 255.0f alpha:1.0f]];

    [self.label4 setGradientEndColor:[UIColor colorWithRed:255.0f / 255.0f green:163.0f / 255.0f blue:64.0f / 255.0f alpha:1.0f]];

 

3、FXLabel也提供了很多特效支持,具体的看例子,很详细。

4、动画

CGPoint orgPos = label.center;

CGFloat move = label.frame.size.height;

label.hidden = NO;



[UIView animateWithDuration:0.12

                                  delay:0.0f

                                options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction

                             animations:^(void) {

                                 // 上昇

                                 label.center = CGPointMake(orgPos.x, label.center.y - move);

                                 label.alpha = 1.0;

                             }

                             completion:^(BOOL finished) {

                                 

                                 [UIView animateWithDuration:0.2

                                                       delay:0

                                                     options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction

                                                  animations:^(void) {

                                                      label.center = orgPos;

                                                      label.alpha = 0.0;

                                                  }

                                                  completion:^(BOOL finished) {

                                                      label.hidden = YES;

                                                  }];

                             }];

 

你可能感兴趣的:(UILabel)