首页 > 移动平台 > 详细

IOS 制作版本新特性

时间:2017-03-30 22:49:51      阅读:258      评论:0      收藏:0      [点我收藏+]

 

创建版本新特性 页面(存放图片)

HMNewfeatureViewController.m

技术分享
#define HMNewfeatureImageCount 4
#import "HMNewfeatureViewController.h"
#import "HMTabBarViewController.h"

@interface HMNewfeatureViewController ()<UIScrollViewDelegate>
@property(nonatomic,weak) UIPageControl *pageControl;

@end

@implementation HMNewfeatureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //1.添加UISrollView
    [self setupScrollView];
    //2.添加pageControl
    [self setupPageControl];
    
}
/**
 *添加UISrollView
 *
 */
-(void)setupScrollView
{
    //添加UISrollView
    UIScrollView *scrollView=[[UIScrollView alloc]init];
    scrollView.frame=self.view.frame;
    scrollView.delegate=self;
    [self.view addSubview:scrollView];
    
    //添加图片
    CGFloat imageW=scrollView.width;
    CGFloat imageH=scrollView.height;
    for (int i=0; i<HMNewfeatureImageCount; i++) {
        //创建UIImageView
        UIImageView *imageView=[[UIImageView alloc]init];
        NSString *name=[NSString stringWithFormat:@"new_feature_%d",i+1];
        if(FourInch)
        {
            name=[name stringByAppendingString:name];
        }
        imageView.image=[UIImage imageNamed:name];
        
        [scrollView addSubview:imageView];
        
        //设置frame
        imageView.y=0;
        imageView.x=i*imageW;
        imageView.width=imageW;
        imageView.height=imageH;
        // 给最后一个imageView添加按钮
        if (i == HMNewfeatureImageCount - 1) {
            [self setupLastImageView:imageView];
        }

    }
    
    //3.设置其他属性
    scrollView.contentSize=CGSizeMake(HMNewfeatureImageCount*imageW, 0);
    scrollView.pagingEnabled=YES;//是否图片做分页显示
    scrollView.showsHorizontalScrollIndicator=NO;//是否显示水平滚动条
    scrollView.backgroundColor= HMColor(246, 246, 246);
}
/**
 *添加pageControl
 *
 */
-(void)setupPageControl
{

    //1.添加
    UIPageControl *pageControl=[[UIPageControl alloc]init];
    pageControl.numberOfPages=HMNewfeatureImageCount;
    pageControl.centerX = self.view.width * 0.5;
    pageControl.centerY=self.view.height-30;
    [self.view addSubview:pageControl];
    
    //设置圆点的颜色
    pageControl.currentPageIndicatorTintColor=HMColor(253, 98, 42);    // 当前页的小圆点颜色
    pageControl.pageIndicatorTintColor=HMColor(189, 189, 189); // 当前页的小圆点颜色

    self.pageControl=pageControl;
}

/**
 *设置最后一个UIImageView的内容
 *
 */
-(void)setupLastImageView:(UIImageView *)imageView
{

    imageView.userInteractionEnabled=YES;
    
    //添加开始按钮
    [self setupStartButton:imageView];
    
    //添加分享按钮
    [self setupShareButton:imageView];
}
/**
 *添加开始按钮
 *
 */
-(void)setupStartButton:(UIImageView *)imageView
{
    //1.添加开始按钮
    UIButton *startButton=[[UIButton alloc]init];
    

    //2.设置背景图片
    [startButton setBackgroundImage:[UIImage imageWithName:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [startButton setBackgroundImage:[UIImage imageWithName:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
    
    //3.设置frame
    startButton.size=startButton.currentBackgroundImage.size;
    startButton.centerX=self.view.width*0.5;
    startButton.centerY=self.view.height*0.8;
    
    
    //4.设置文字
    [startButton setTitle:@"开始微博" forState:UIControlStateNormal];
    [startButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [startButton addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchUpInside];

    
    
    [imageView addSubview:startButton];
}
/**
 *开始微博
 *
 */
-(void)start{

    HMTabBarViewController *vc=[[HMTabBarViewController alloc]init];
    
    //切换控制器
    UIWindow *window=[UIApplication sharedApplication].keyWindow;
    window.rootViewController=vc;
    /*切换控制器的3种方式
    // push : [self.navigationController pushViewController:vc animated:NO];
    // modal : [self presentViewController:vc animated:NO completion:nil];
    // window.rootViewController : window.rootViewController = vc;
     */
}

/**
 *添加分享按钮
 *
 */
-(void)setupShareButton:(UIImageView *)imageView
{
    //1.添加分享按钮
    UIButton *shareButton=[[UIButton alloc]init];

    //2.设置文字和图标
    [shareButton setTitle:@"分享给大家" forState:UIControlStateNormal];
    [shareButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [shareButton setImage:[UIImage imageWithName:@"new_feature_share_false"] forState:UIControlStateNormal];
    [shareButton setImage:[UIImage imageWithName:@"new_feature_share_true"] forState:UIControlStateSelected];
    
    //3. 设置frame
    shareButton.size=CGSizeMake(150, 35);
    shareButton.centerX=self.view.width *0.5;
    shareButton.centerY=self.view.height *0.7;
    
    //监听点击
    [shareButton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
    
    // 4.设置间距
    // top left bottom right
    // 内边距 == 自切
    // 被切掉的区域就不能显示内容了
    // contentEdgeInsets : 切掉按钮内部的内容
    //    shareButton.contentEdgeInsets = UIEdgeInsetsMake(10, 20, 10, 20);
    // imageEdgeInsets : 切掉按钮内部UIImageView的内容
    //    shareButton.imageEdgeInsets = UIEdgeInsetsMake(5, 5, 5, 5);
    // titleEdgeInsets : 切掉按钮内部UILabel的内容
    shareButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    
    [imageView addSubview:shareButton];
}

/**
 分享
 */
- (void)share:(UIButton *)shareButton
{
    shareButton.selected = !shareButton.isSelected;
    //    UIImage *falseImage = [UIImage imageWithName:@"new_feature_share_false"];
    //    if (shareButton.currentImage == falseImage) {
    //        [shareButton setImage:[UIImage imageWithName:@"new_feature_share_true"] forState:UIControlStateNormal];
    //    } else {
    //        [shareButton setImage:falseImage forState:UIControlStateNormal];
    //    }
}

#pragma mark--UIScrollViewDeleage
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{

    //获得页码
    CGFloat doublePage=scrollView.contentOffset.x /scrollView.width;
    int intPage=(doublePage+0.5);
    
    //设置页码
    self.pageControl.currentPage=intPage;
}
-(void)dealloc{
    HMLog(@"dealloc----");
}
View Code

 

AppDelegate.m 调用HMNewfeatureViewController.m

 

#import "AppDelegate.h"
#import "HMTabBarViewController.h"
#import "HMNewfeatureViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    
    application.statusBarHidden=NO;
    
    //1.创建窗口
    self.window=[[UIWindow alloc]init];
    self.window.frame=[UIScreen mainScreen].bounds;
    
    /*
    //2.设置窗口的根控制器
    UITabBarController *tabbarVc=[[HMTabBarViewController alloc]init];
    self.window.rootViewController=tabbarVc;
    */
    
    //如果知道第一次使用这个版本?比较上次的使用情况
    NSString *versionKey=(__bridge NSString *)kCFBundleVersionKey;
    
//从沙盒中取出上次存储的软件版本号(取出用户上次的使用记录)
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    NSString  *lastVersion=[defaults objectForKey:versionKey];
    
    //获得当前打开软件的版本号
    NSString *currentVersion=[NSBundle mainBundle].infoDictionary[versionKey];
    
    if([currentVersion isEqualToString:lastVersion])
    {
        self.window.rootViewController=[[HMTabBarViewController alloc]init];
    }
    else
   {
//新特性页面 self.window.rootViewController
= [[HMNewfeatureViewController alloc] init]; //存储这次使用的软件版本 [defaults setObject:currentVersion forKey:versionKey]; [defaults synchronize]; } //3.显示窗口(成为主窗口) [self.window makeKeyAndVisible]; return YES; }

 

IOS 制作版本新特性

原文:http://www.cnblogs.com/liuwj/p/6648836.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!