年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3018|回复: 0

轻松搭建新特性界面、向导页

[复制链接]
  • TA的每日心情
    奋斗
    2022-12-13 21:26
  • 签到天数: 371 天

    [LV.9]以坛为家II

    发表于 2014-8-2 17:47:38 | 显示全部楼层 |阅读模式
    1、应用场景
    新软件安装在第一次打开时都会有该软件或版本的介绍,在iOS中最经典的做法是搭建一个ScrollView分页展示
    但考虑到iPhone4系统与iPhone5系统,屏幕适配如何更为科学简单是一门学问,以下提供一个参考

    2、图片命名
    一般是三图片,Retina屏之前屏幕一套、iPhone4(4S)一套、iPhone5(5C/5S)一套
    xxx_序号.png                   // iPhone3GS及以前,可忽略
    xxx_序号@2x.png            // iPhone4及iPhone4S
    xxx_序号[email protected]  // iPhone5及iPhone5C、iPhone5S
    如:
    new_feature_1.png
    [email protected]
    [email protected]
    new_feature_2.png
    [email protected]
    [email protected]
    new_feature_3.png
    [email protected]
    [email protected]

    3、文件名自动识别3.1、增加两个Category
    NSString+SA
    1. //
    2. //  NSString+SA.m
    3. //  SianWeibo
    4. //
    5. //  Created by yusian on 14-4-12.
    6. //  Copyright (c) 2014年 小龙虾论坛. All rights reserved.
    7. //  自定义字符串拼接方法
    8. #import "NSString+SA.h"
    9. @implementation NSString (SA)
    10. - (NSString *)fileAppend:(NSString *)string
    11. {
    12.     // 1、获取文件扩展名
    13.     NSString *ext = [self pathExtension];
    14.    
    15.     // 2、去掉文件扩展名
    16.     NSString *str = [self stringByDeletingPathExtension];
    17.    
    18.     // 3、拼接新加字符串
    19.     str = [str stringByAppendingString:string];
    20.    
    21.     // 4、拼接扩展名
    22.     str = [str stringByAppendingPathExtension:ext];
    23.    
    24.     return str;
    25. }
    26. @end
    复制代码
    UIImage+SA
    1. //
    2. //  UIImage+SA.m
    3. //  SianWeibo
    4. //
    5. //  Created by yusian on 14-4-11.
    6. //  Copyright (c) 2014年 小龙虾论坛. All rights reserved.
    7. //  
    8. // 判断是否为iphone5的宏
    9. #define isIPhone5 ([UIScreen mainScreen].bounds.size.height == 568)
    10. #import "UIImage+SA.h"
    11. #import "NSString+SA.h"
    12. @implementation UIImage (SA)
    13. + (UIImage *)fullScreenImage:(NSString *)string
    14. {
    15.     // 根据屏幕高度判断iphone5
    16.     if (isIPhone5) {
    17.         
    18.         string = [string fileAppend:@"-568h@2x"];
    19.    
    20.     }
    21.     return [self imageNamed:string];
    22. }
    23. // 自动拉伸图片
    24. + (UIImage *)resizeImage:(NSString *)imageName
    25. {
    26.     UIImage *image = [UIImage imageNamed:imageName];
    27.     return [image stretchableImageWithLeftCapWidth:5 topCapHeight:5];
    28. }
    29. @end
    复制代码
    4、创建ScrollView(关键代码)
    1. #pragma mark 2.1、添加scrollView控件
    2. - (UIScrollView *)creatScrollView       // 控件的创建单独抽象成方法
    3. {
    4.     // 创建scrollView设置尺寸位置及相关属性
    5.     UIScrollView *scrollView = [[UIScrollView alloc] init];
    6.     scrollView.frame = self.view.bounds;
    7.     scrollView.contentSize = CGSizeMake(_size.width * kPicCount, 0);
    8.     scrollView.pagingEnabled = YES;
    9.     scrollView.showsHorizontalScrollIndicator = NO;
    10.     scrollView.delegate = self;
    11.    
    12.     //  创建新特性图片设置尺寸位置并添加到scrollView
    13.     for (int i = 0; i < kPicCount; i++) {
    14.         UIImageView *imageView = [[UIImageView alloc] init];
    15.         [scrollView addSubview:imageView];
    16.         NSString *imageName = [NSString stringWithFormat:@"new_feature_%d.png", i + 1];
    17.         imageView.image = [UIImage fullScreenImage:imageName];
    18.         imageView.frame = CGRectMake(_size.width * i, 0, _size.width, _size.height);
    19.     }
    20.     return scrollView;
    21. }
    复制代码


    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-4-29 07:40 , Processed in 0.049593 second(s), 19 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表