新浪微博 有道云笔记 麦库 EverNote Pocket Instapaper 更多

01-UIScrollView01-大图片展示

 

 

 

  1. //
  2. //  MJViewController.m
  3. //  01-UIScrollView01-大图片展示
  4. //
  5. //  Created by apple on 13-11-27.
  6. //  Copyright (c) 2013 itcast. All rights reserved.
  7. //

  8. #import "MJViewController.h"

  9. @interface MJViewController ()

  10. @end

  11. @implementation MJViewController

  12. - (void)viewDidLoad
  13. {
  14.     [super viewDidLoad];
  15.     
  16.     UIScrollView *scrollView = [[UIScrollView alloc] init];
  17.     scrollView.frame = CGRectMake(0, 0, 250, 250); // UIScrollView的可视范围
  18.     scrollView.backgroundColor = [UIColor grayColor];
  19.     [self.view addSubview:scrollView];
  20.     
  21.     UIImageView *imageView = [[UIImageView alloc] init];
  22.     imageView.image = [UIImage imageNamed:@"big.jpg"];
  23.     CGFloat imgW = imageView.image.size.width; // 图片的宽度
  24.     CGFloat imgH = imageView.image.size.height; // 图片的高度
  25.     imageView.frame = CGRectMake(0, 0, imgW, imgH);
  26.     [scrollView addSubview:imageView];
  27.     
  28.     // 设置UIScrollView的滚动范围(内容大小)
  29.     scrollView.contentSize = imageView.image.size; 
  30.     // 隐藏水平滚动条
  31.     scrollView.showsHorizontalScrollIndicator = NO;
  32.     scrollView.showsVerticalScrollIndicator = NO;
  33.     
  34.     // 去掉弹簧效果
  35. //    scrollView.bounces = NO;
  36.     
  37.     // top  left  bottom  right
  38.     scrollView.contentInset = UIEdgeInsetsMake(10, 20, 40, 80);
  39. }

  40. @end

https://www.evernote.com/shard/s227/sh/5e562326-d7af-4b51-8134-42fa544fd979/786f6301ad10be5c5ae80ba3bef5031a

posted @ 2013-12-25 17:01  iTeaTime(技术清谈)  阅读(202)  评论(0编辑  收藏  举报