IOS的新生助手

九月马上就要来临,为了不让新来的学弟学妹们迷路,好心的学长在做出了专为新僧的助手。


这里主要推荐IOS的图片插入,一个界面的有很多个Button按钮,每一个Button按钮都有自己独特的功能,但是光是一个按钮就会显得很丑,这时只要将一张图片做成一个按钮,在用户”不小心”点击图片的时候跳转界面,实现Button的功能,这样就会显得更漂亮一些。

比如:点击下图的院内风景时:


会出现


等等图片。


Rootview中的编辑以下代码

-(void)setButton{

UIImage*ii=[UIImage imageNamed:@"Resource/button2.png"];

    UIButton *button2=[UIButtonbuttonWithType:UIButtonTypeCustom];

    [button2setFrame:CGRectMake(self.view.frame.size.width/2 - 125,self.view.frame.size.height/2 +9, 250, 84)];

    [button2 setBackgroundImage:iiforState:UIControlStateNormal];

    [button2 addTarget:selfaction:@selector(beginforview2) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button2];

-(void)beginforview2{

    self.thrid=[[ViewController alloc]init];

    thrid.title=@"院内景色";

    [self.navigationControllerpushViewController:thrid animated:YES];

}

别忘了在- (void)viewDidLoad中添加[self setButton];

这样就会跳转到下一个界面,再此界面的- (void)viewDidLoad中添加

UIBarButtonItem*leftButton = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:selfaction:@selector(selectLeftAction:)];

    self.navigationItem.leftBarButtonItem =leftButton;

   

    CGRect scrollViewRect = CGRectMake(0, - 22,self.view.frame.size.width, self.view.frame.size.height + 44);

    NSInteger picNum = 9;

   

    self.myScrollView = [[UIScrollView alloc]initWithFrame:scrollViewRect];

    self.myScrollView.pagingEnabled = YES;

    self.myScrollView.contentSize =CGSizeMake(scrollViewRect.size.width * picNum,scrollViewRect.size.height);

    myScrollView.pagingEnabled = YES;

    myScrollView.showsHorizontalScrollIndicator= NO;

    myScrollView.showsVerticalScrollIndicator =NO;

    [self.view addSubview:self.myScrollView];

   

    NSInteger i;

    UIImageView * imageView;

    CGRect imageViewRect = self.view.bounds;

    for(i = 0;i < picNum ;i++){

        UIImage * pic = [UIImage imageNamed:[NSStringstringWithFormat:@"PicInSchool/Yndt%d.png",i]];

        imageView = [self newImageViewWithImage:picframe:imageViewRect];

        [self.myScrollViewaddSubview:imageView];

        imageViewRect.origin.x +=imageViewRect.size.width;

}

就会让图片一张一张的显示出来,通过手指向右或者向左滑动即可预览。但是关键是图片的位置要对,想要展示的序号必须从0开始一个一个排列正确。

 

当学长完成这个项目的时候感到IOS会做,会用之后就会变得很简单,学得时候由于才刚接触,确实难以理解。但是作为技术人员,寂寞和无尽的锻炼是必须的,只有不断的练习,不断的优化代码,改良自己才能跟上时代,不至于被淘汰。在做的过程中遇到了很多困难,但是绝对不可以放弃,只能自己一个一个的攻略,最后看到自己的努力能为别人带来帮助的那份快乐也只有感受过才能理解。

 

计算机的痛苦是因为计算机的无限可能!


~禹顺



















  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值