iOS笔记-程序员宅基地

技术标签: iOS  ios  

July 27, 2016
作者:dengshuai_super
出处:http://blog.csdn.net/dengshuai_super/article/details/52050398
声明:转载请注明作者及出处。


✓   2015.6.4 周四

file’s owner以及outlet与连线的理解

file’s owner 可以看作是xib对应的类,比如view对应的xib文件的file‘s owner
对应的就是view controller的类。

我对file’s owner 的理解:xib文件附属于一个类,这个类就是xib属性栏中的custom Class,并且custom Class一般是控制器类A。而file’s owner相当于这个控制器类A。现在需要对控制器A中定义的类 和 xib中的形象化的控制器类B进行连接,只要从file’s owner 拖到对应的控制器B进行连接。这个过程相当对把A中的某个属性(一般都是定义的类IBOutlet)和B中的控件或者视图或者控制器对应起来。
而事件的连接的过程则相当于将B中的某个执行动作和A中的某个方法(IBAction)

view和viewController之间的对应关系,需要一个桥梁来进行连接(即,对于一个视图,他如何知道自己的界面的操作应该由谁来响应),这个桥梁就是File’s
Owner。

选中某个XIB的File’s Owner ,在Inspector中可以看到属性:File Name和Custom Class,该File’s Owner 就是用来绑定File Name中的xib文件和Custom Class中的ViewController的,在做了这个绑定之后,按住control键,拖动File‘s Owner 到xib中的某个控件的时候,就是Custom Class中定义的IBOutlet元素与xib中元素中进行连接的过程,同样,拖动“xib中的控件的动作”到File’s Owner的时候,就是将xib中该动作的响应与Custom Class中某个IBAction进行连接的过程。

xib文件本身可以看作是一个xml,app启动的时候会根据xml构造的xib对应的界面及其控件。

✓   2015.6.19周五

http://blog.csdn.net/q199109106q/article/details/8563438/

✓   2015.6.22周一

http://mobile.51cto.com/iphone-388248.htm

4、打开ViewController.m,找到addButton函数,添加以下代码:

    1.  - (IBAction)addButton:(id)sender { 
    2.      //动态添加一个按钮 
    3.      CGRect frame = CGRectMake(300, 300, 300, 50);  
    4.      UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
    5.      button.frame = frame; 
    6.      [button setTitle:@"新添加的动态按钮" forState: UIControlStateNormal];   
    7.      button.backgroundColor = [UIColor clearColor];   
    8.      button.tag = 2000; 
    9.      [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];   
    10.     [self.view addSubview:button];   
    11. } 

5、在addButton函数后边添加一个函数:

    1.  //这个是新按钮的响应函数 
    2.  -(IBAction) buttonClicked:(id)sender {   
    3.      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"  
    4.                                                      message:@"单击了动态按钮!"    
    5.                                                     delegate:self    
    6.                                            cancelButtonTitle:@"确定"   
    7.                                            otherButtonTitles:nil];   
    8.      [alert show]; 
    9.      [alert release]; 
    10. } 
    11. 

在深色背景下将状态条设置成白色:

在老版本的iOS中,状态栏永远都是白色风格。而在iOS 7中,我们可以修改每个view controller中状态栏的外观。通过UIStatusBarStyle常量可以指定状态栏的内容是暗色或亮色。默认情况下,状态栏的显示是暗色。也就是说,状态栏上的时间、电池指示器和Wi-Fi信号显示为暗色。如果导航栏中使用暗色为背景

-(UIStatusBarStyle)preferredStatusBarStyle 
{ 
    return UIStatusBarStyleLightContent; 
}

通过tag值获得相应对象

UITabBarItem *shouye = (UITabBarItem *)[self.view viewWithTag:100];

改变TabBarItem的选中时和未选中时的图片
UITabBarItem *ti1 = [tabBar.items objectAtIndex:0];
ti1.title = @”梦见”;

ti1.image = [[UIImage imageNamed:@"qr_tabbar_mine"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
ti1.selectedImage = [[UIImage imageNamed:@"qr_tabbar_mine_hl"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 

http://www.bkjia.com/IOSjc/872299.html
3.以上拖拽工作到此结束,下面要实现我们的业务逻辑和关联视图之间的关系,为了关联视图时能找到带有三个按钮的视图,我们需要设置一下该视图的StoryboardID,入下图

  4.下面来编写我们的代码,上面我们用到了TextField,我们需要处理键盘的回收事件,所以我们的ViewController要遵守UITextFiledDelegate协议,实现有关键盘的方法
    (1)遵守UITextFieldDelegate协议

#import <UIKit/UIKit.h>   
@interface ViewController : UIViewController<UITextFieldDelegate> 
@end

    (2)在ViewController.m中中进行回调注册和实现协议中相应的方法,代码如下:

-(BOOL) textFieldShouldReturn:(UITextField *)textField {     
[self.userName resignFirstResponder];     [self.password resignFirstResponder];    
return YES; 
}   
- (void)viewDidLoad {     
[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.    self.userName.delegate = self;     self.password.delegate = self; 
- }

  5.处理完键盘的事儿,就该处理我们当登陆按钮点击时回调的事件了,首先在回调方法中获取TextFiled的值,由值的情况来实现是否进行页面间的切换。 在页面切换时我们得关联两个页面中的关系。

- (IBAction)tapButton:(id)sender {           
if ([username isEqualToString:@"admin"] && [password isEqualToString:@"admin"])     
{
//获取storyboard: 通过bundle根据storyboard的名字来获取我们的storyboard,         
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];    //由storyboard根据myView的storyBoardID来获取我们要切换的视图        
UIViewController *myView = [story instantiateViewControllerWithIdentifier:@"myView"];//由navigationController推向我们要推向的view         
[self.navigationController pushViewController:myView animated:YES];               
}   
}

 代码说明:关联两个View需要三部
1.获取storyboard: 通过bundle的名获取bundle, 在通过storyborad的名字来获取我们的storyboard;
2.在由storyboard获取storyboardID是myView的View;
3.执行由当前View推向我们获取到的myView;

使用storyboard,设置tab bar Item的选中图片(selected Image)
http://blog.csdn.net/sxh1234567/article/details/44984665

                                       9:16


这里写图片描述

http://www.cocoachina.com/ios/20141230/10800.html
快速兼容iPhone5s和6,6plus

✓   2015.6.23 周二
static NSString *CellIdentifier= @"CellIdentifier";

#define PLISTFILENAME @"SpeMerchantPList.plist"

#define PATH  [[NSBundle mainBundle]pathForResource:PLISTFILENAME ofType:nil]

- (void)viewDidLoad {
    [super viewDidLoad];
   // [_SpecialMerchantTableView setBackgroundColor:[UIColor grayColor]];//把背景色改为黑色背景
    _SpeMerchantInfoArray = [NSArray arrayWithContentsOfFile:PATH];

    [self.tableView registerClass:[UITableViewCell class]  forCellReuseIdentifier:CellIdentifier];

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [_SpeMerchantInfoArray count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    // Configure the cell...
    if ([_SpeMerchantInfoArray count]>0)
    {

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(7, 7, 100, 70)];
        imageView.image = [UIImage imageNamed:_SpeMerchantInfoArray[indexPath.row][0]];
        [cell addSubview:imageView];

        UILabel *TitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(115, 8, 95, 21)];
        TitleLabel.text = _SpeMerchantInfoArray[indexPath.row][1];
        [cell addSubview:TitleLabel];

        UILabel *DateLabel = [[UILabel alloc]initWithFrame:CGRectMake(121, 39, 160, 17)];
        DateLabel.text = _SpeMerchantInfoArray[indexPath.row][2];
        DateLabel.backgroundColor = [UIColor clearColor];
        DateLabel.textColor = [UIColor grayColor];
        DateLabel.font = [UIFont fontWithName:@"STHeiti-Medium.ttc" size:5];
        [cell addSubview:DateLabel];

        UILabel *JuLiLabel = [[UILabel alloc]initWithFrame:CGRectMake(240, 7, 63, 21)];
        JuLiLabel.text = _SpeMerchantInfoArray[indexPath.row][3];
        [cell addSubview:JuLiLabel];

        UIButton *zuobiaoButton = [[UIButton alloc]initWithFrame:CGRectMake(215, 7, 20, 20)];
       // [zuobiaoButton.imageView setImage:[UIImage imageNamed:@"zaixiandaohang"] ];
        [zuobiaoButton setImage:[UIImage imageNamed:@"zaixiandaohang"] forState:UIControlStateNormal];
        [cell addSubview:zuobiaoButton];

        UIButton *moneyButton = [[UIButton alloc]initWithFrame:CGRectMake(303, 7, 20, 20)];
        //[moneyButton.imageView setImage:[UIImage imageNamed:@"caifu"] ];
        [moneyButton setImage:[UIImage imageNamed:@"caifu"] forState:UIControlStateNormal ];
        [cell addSubview:moneyButton];


    }


    return cell;
}
✓   2015.6.24 周三

http://www.cocoachina.com/bbs/read.php?tid-281373.html

//自定义按钮,文字在左,图片在右
HHButton *btn = [[HHButton alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];//宽100,高30只是最大的显示面积。 
[btn setTitle:@"山东省青岛市" forState:UIControlStateNormal]; 
[btn setImage:[UIImage imageNamed:@"小三角"  forState:UIControlStateNormal]; 


 [[UITabBar appearance] setSelectedImageTintColor:[UIColor orangeColor]];

init-初始化程序
viewDidLoad-加载视图
viewWillAppear-UIViewController对象的视图即将加入窗口时调用;
viewDidApper-UIViewController对象的视图已经加入到窗口时调用;viewWillDisappear-UIViewController对象的视图即将消失、被覆盖或是隐藏时调用;viewDidDisappear-UIViewController对象的视图已经消失、被覆盖或是隐藏时调用;didReceiveMemoryWarning - 内存不足时候调用这个

当利用ScrollView实现滚动页面时,初始化ScrollView时CGRectMake当width要设置成ScreenWidth,而它的ContentSize的宽度设置成实际内容所需要的宽度,例如有3张图片则设置成3倍图片的宽度。

http://www.cnblogs.com/woainilsr/archive/2012/03/28/2421881.html

length = (self.view.frame.size.width-40)/6;
    Scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0, smallScroll.frame.origin.y+smallScroll.frame.size.height, screenWidth, length*1.8)];
    Scroll.bounces = NO;
    Scroll.backgroundColor=[UIColor whiteColor];
    Scroll.showsHorizontalScrollIndicator = NO;
    Scroll.pagingEnabled = YES;
    Scroll.delegate = self;
    Scroll.contentSize = CGSizeMake(self.view.frame.size.width*2, length*1.8);
    [scrollView addSubview:Scroll];

Scroll.contentSize = CGSizeMake(self.view.frame.size.width*buttonTitleArr.count/4, length*1.8);
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/dengshuai_super/article/details/52050398

智能推荐

python 自省_Python自省指南-程序员宅基地

文章浏览阅读612次。什么是内省? 在日常生活中,自省是自我检查的行为。 内省是指对自己的思想,感觉,动机和行为的检查。 伟大的哲学家苏格拉底(Socrates)将一生的大部分时间都花在自我检查上,鼓励他的雅典人也这样做。 他甚至声称,对他来说,“未经检查的生活是不值得生活的”。 (请参阅相关主题的链接以获得更多关于苏格拉底。) 在计算机程序设计中,自省是指检查某事物以确定它是什么,它知道什么以及它能够做什..._you are now leaving help and returning to the python interpreter. if you wan

python jupyter_两个星期入门Python,Jupyter神器来帮助-程序员宅基地

文章浏览阅读166次。Jupyter 是一款开放性的代码编写软件,最大的特点是能够实时运行代码,查看输出效果。同时该软件集成了多种插件,能够实现非常复杂的功能。对于初学者而言,因为Jupyter具有良好的交互性,方便看到每一行、每一个代码块的输出结果,Jupyter成为众多Python初学者的青睐。Jupyter已经成为Python学习的基础配置Python环境安装对于刚刚开始学习python的初学者,建议下载anac..._用jupyter使用python语言构建神经网络设计预测股票

Maven的dependency和dependencyManagement的区别_maven dependencies和devdependencies-程序员宅基地

文章浏览阅读1w次,点赞7次,收藏11次。dependencies:就算在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项(全部继承)dependencyManagement:只是声明依赖,并不实现引入,因此子项目需要显示声明需要用的依赖。如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自_maven dependencies和devdependencies

pygame安装教程python3.7.3_python3安装pygame-程序员宅基地

文章浏览阅读170次。前言在学习python的pygame库的时候,需要安装pygame,然后百度一下怎么安装的,教程基本都是说要下载whl文件,下载地址:https://pypi.org/project/pygame/#files然后使用python -m pip install --user pygame-xxx-win64.whl安装,这应该是很早版本的安装方法了,导致我那么去安装总是报如下错:ERROR: py..._python3.7.3的pygame

Python爬虫报错 cannot import name 'etree' from 'lxml'_linux环境 cannot import name 'etree' from 'lxml-程序员宅基地

文章浏览阅读1.8k次。我的原因是文件名是新建时的名字没有改改成first.py之后运行就没问题了_linux环境 cannot import name 'etree' from 'lxml

FastJson 比较_fastjson 对象比较-程序员宅基地

文章浏览阅读612次。# 概述JSON不管是在Web开发还是服务器开发中是相当常见的数据传输格式,一般情况我们对于JSON解析构造的性能并不需要过于关心,除非是在性能要求比较高的系统。目前对于Java开源的JSON类库有很多种,下面我们取4个常用的JSON库进行性能测试对比, 同时根据测试结果分析如果根据实际应用场景选择最合适的JSON库。这4个JSON类库分别为:Gson,FastJ..._fastjson 对象比较

随便推点

java mina 大文件传输_超大文件如何快速传输给上万用户?-程序员宅基地

文章浏览阅读293次。日常我们使用网盘或在线传输文件工作时不大容易遇到超级大的文件(50G以上单个文件),所以大多数网盘或在线传输工具都能轻松应对。但如测绘、电影原片分发、科学研究产生的数据包.....这些文件单个就可以轻松达到100G甚至1TB以上,如何处理和传输这些文件就需要较长的技术储备及实施经验。当文件的尺寸超过一定的范围,做到稳定高速传输的难点就指数级增大,也会遇到很多极限限制。譬如:FAT32分区最大单个文..._java接口上万数据传输

hive linux时间戳转换函数,hive 常用函数整理 5.日期函数-程序员宅基地

文章浏览阅读303次。1. UNIX时间戳转日期函数: from_unixtime语法: from_unixtime(bigint unixtime[, string format])返回值: string说明: 转化UNIX时间戳(从1970-01-01 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式举例:hive> select from_unixtime(1323308943,'yyyyMM..._hive取linux绝对秒

Java中将Map转String,String转Map_string转map<string, object>-程序员宅基地

文章浏览阅读2.6k次。暴力的直接Map对象toString()存,后面取出是就是用再转换为MapString转Map:JSONObject jsonobject = JSONObject.fromObject(str);rMap = (Map<String, Object>) jsonobject;但很多时候并不能直接将Map对象的toString()而是应该转换为JsonObject后再调用toString()后存入就正常了Map<String,Object> map=new HashMa_string转map

java 全局快捷键_java全局快捷键--jintellitype-程序员宅基地

文章浏览阅读456次。java全局快捷键--jintellitype1. 简介Java本身是无法对桌面进行全局键盘监听的,无法设置全局快捷键,当焦点从java程序面板失去时,自带的监听器就无法监听了一些程序是需要全局快捷键操作的,此时就可以使用第三方包JIntellitype来实现全局快捷键注册。本质上还是调用了dll动态链接库向该第三方库注册快捷键的时候,需要指定一个int标识码,用于代表快捷键。当用户按下快捷键的时..._jintellitype java

webpack 优化 浏览器缓存 hash 、 chunkHash、contentHash_输出文件名的 hash、chunkhash 和 contenthash 缓存-程序员宅基地

文章浏览阅读665次。hash一般是结合CDN缓存来使用,通过webpack构建之后,生成对应文件名自动带上对应的MD5值。如果文件内容改变的话,那么对应文件哈希值也会改变,对应的HTML引用的URL地址也会改变,触发CDN服务器从源服务器上拉取对应数据,进而更新本地缓存。但是在实际使用的时候,这几种hash计算还是有一定区别。 hash 值..._输出文件名的 hash、chunkhash 和 contenthash 缓存

JAVA------String_strs.indexof('02')!=-1-程序员宅基地

文章浏览阅读555次。------- android培训、java培训、期待与您交流! ----------一,String中常见功能 1,获取 1.1 字符串中包含的字符数,也就是字符串的长度 int length():获取长度。 1.2 根据位置获取位置上某个字符 int charAt(int index):当访问到字符串中不存在的角标时,_strs.indexof('02')!=-1

推荐文章

热门文章

相关标签