UILabel和UIImageView的使用

jopen 9年前發布 | 22K 次閱讀 UILabel iOS開發 移動開發

UILabel的使用

主要功能:顯示文本用于內容提示

常用屬性

NSString         *text; //UILabel顯示的文本內容;

UIColor *textColor; //文本顯示的顏色

CGSize *shadowColor; //文本顯示的陰影

NSTextAlignment textAlignment;//文本對齊方式(左對齊,居中,右對齊)

UIColor *highlightedtextColor;//文本高亮是的顯示顏色

BOOL highlighted; //設置文本高亮

NSLineBreakMode lineBreakMode; //如果需要多行顯示需要設置這個屬性

BOOL userInteractionEnabled; //UILabel是否允許交互

NSInteger numberOfLines;// UILabel文本顯示的行數,如果是0表示不限制

BOOL adjustsFontSizeToFitWidth;//根據UILabel大小調整字體大小</pre>

UIImageView 的使用

主要功能:在應用程序中主要用于顯示圖片的視圖

常用屬性

UIImage          *image;
//UIImageView顯示的圖片內容,默認是nil

UIImage *highlightedImage; //當UIImageView被選中的時候顯示的圖片內容 默認是nil

BOOL userInteractionEnabled; //UIImageView及其上得元素是否交互(非常重要)

BOOL highlighted;//UIImageView是否是高亮狀態</pre>

初始化方法

- (id)initWithImage:(UIImage*)image;

- (id)initWithImage:(UIImage*)image highlightedImage:(UIImage*)highlightedImage;

制作動畫播放效果

#import "ViewController.h"

@interface ViewController ()

@property(strong,nonatomic) UIImageView *imageView;

@end

@implementation ViewController

  • (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //定義一個存放圖片對象的數組 NSArray *imagesArray = [[NSArray alloc] initWithObjects:

                          [UIImage imageNamed:@"xiaohai.jpg"],
                          [UIImage imageNamed:@"xiaogou.jpg"],
                          [UIImage imageNamed:@"songshu.jpg"],
                          nil];
    

    //初始化一個圖片視圖 _imageView = [[UIImageView alloc] initWithFrame: CGRectMake(100, 150, 150, 180)];

    //將圖片數組賦值給圖片視圖的動畫圖片 _imageView.animationImages = imagesArray;

    //設置圖片按照原始比例縮放。保持縱橫比 _imageView.contentMode = UIViewContentModeScaleAspectFit;

    //切換動作的持續時間,秒 _imageView.animationDuration = 2;

    //動畫的重復次數,0時自由循環 _imageView.animationRepeatCount = 0;

    [self.view addSubview:_imageView];

}

  • (IBAction)playAnimation:(id)sender { if (_imageView.isAnimating) {
      [_imageView stopAnimating];//暫停播放
    
    }else{
      [_imageView startAnimating];//開始播放
    
    } }</pre>
 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!