iOS自己写的一些容易忘记的小知识




ios7中,会对selectedImage的图片再次渲染为蓝色。若想显示原图,必须告诉它,不要渲染。

uiimage *selectImage = [uiimage imagenamed:@“sdf”];

selectedImage = [selectedImage imageWithRenderingMode:uiimageRenderingModeAlwaysOriginal];

//声明这张图为原图



xcode 补全插件地址:前往个人资料库—application support—developer—xcode—


UIBarButtonItem appearance  item的外观设置

这样的话,toolBar 的字体也是这个外观设置。



当第一次使用类时,调用且仅一次initialize


主题属性 UINavigationBar 为例

UINavigationBar *appearance = UINavigationBar appearance】;

NSMutableDictionary *textAttrs = NSMutableDictionary Dictionary;

textAttrsUITextAttributeTextColor= [UIColor BlackColor];

textAttrs[UITextAttributeFont] = [UIFont boldSystemFontOfSize:17];

[appearance setTitleTextAttributes: textAttrs];




textField.inputAccessoryView = [[[NSBundle mainBundle] loadNibName:@“ds” owner:nil option:nil ] lastObject];



工程-General-Status Bar Style “default”为跟随导航栏颜色


UIOffsetZero是结构体,只要包装成NSValue对象,才能放入字典/数组中

textAttrsUITextAttributeTextShadowOffset= NSValue valueWithUIOffsetUIOffsetZero】;



UISearchBar *bar = UIScarchBar allocinit】;

bar.frame = CGRectMake(0,0,300,35);

self.navigationItem.titleView =bar ;


uitextfield *field = [[uitextfield alloc]init];

field.leftViewMode = uiTextfieldviewmodeAlways

field.clearbuttonMode = uiTextfieldviewmodeAlways



textAlignment 文本的水平对齐方式(text

contentVerticalAignment  内容的垂直方向的对齐方式(UIcontrol

contentHorizontalAignment 内容的水平方向的对齐方式(优先级低于textAlignment

contentMode 内容的对齐方式(UIView



UINavigationItem self.navigationItem   UINavigationItem 继承NSObject,不是UI控件

UINavigationBar 导航控制器顶部的栏(UI控件),UINavigationBar上显示什么内容,取决于当前控制器的navigationItem的属性

//UINavigationBar ViewnavigationItemmodel

//navigationItemUINavigationBar提供显示的数据



//self��️控制器,可以用来设置当前控制器顶部导航栏的内容

UIBarButtonItem 

//self.navigationItem.leftBarButtonItem 设置导航栏左上角的内容

//self.navigationItem.rightBarButtonItem 设置导航栏右上角的内容

//相当于一个按钮

UITabBarItem

//self.tabBarItem  self��️当前控制器 ,可以用来设置当前控制器对应的选项卡标签的内容

//self.tabBar.Item.title  self.tabBar.Item.image  self.tabBar.Item.selectedImage



self.navigationItem.title

self.navigationItem.titleView


UItabBar

UITabBarController底部的选项卡条

UItabBarButton(私有的)

// UItabBar底部的每一个标签,每一个UITabBarButton里面显示什么内容,取决于当前控制器的tabBarItem属性,UItabBarButtonviewtabBarItemmodel


高亮的时候不要调整图片

Btn.adjustImageWhenHighlighted = NO;


KVC的工作原理是找_tabbar。可以用来替换只读属性的控件


NSString Foundation框架

CFStringRef CoroFoundation框架

NSString *a = _bridge NSString*KCFBundleVersionKey ;



3.5 inch retina @2x

4.0 inch retina -568h@2x 只适用于启动图片 (Default.png)


UIbutton *btn

btn.contentEdgeInsets = UIEdgeInsetMake(10,10,10,10) //内边距 ==自切

btn.imageEdgeInsets = UIEdgeInsetMake(10,10,10,10) //切图片

btn.titleEdgeInsets =UIEdgeInsetMake(10,10,10,10) //只切label


NSNotFound -1 枚举值


NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

[defaults setObject:@“sdf” forKey:@“sdf”];

[defaults synchronize]; //立刻更新 同步到defaults文件


 NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

 NSString *filePath = [doc stringByAppendingPathComponent:@"account.data"];

 NSObject *account;

 [NSKeyedArchiver archiveRootObject:account toFile:filePath];

[NSKeyedUnarchiver unarchiveObjectWithObject:filePath ];


当遵守NSCoding 协议时的两个代理

- (void)encodeWithCoder:(NSCoder *)aCoder;


- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder;当从文件中读取一个对象时调用,在该方法中写清楚如何解析文件中的数据 

NSDate *now = [NSDate date];

[now compare:account.expire_time ];


//NSOrderedAscending = -1 ,升序,越往右边越大

//NSOrderedSame ,相等

//NSOrderedDescending ,降序,越往右边越小


KVC属性不足会报错 KVC中的字典会直接赋值,而不是赋给对象


终端中:

—  cd /Users/apple/Documents/运行时/运行时

— ls -l

        — clang -rewrite-objc main.m

 然后会生成main.cpp

    open main.cpp


UIRefreshControl 刷新控件


 44  : cell 的默认高度、导航栏的可见高度

 49 UITabBar的默认高度

 64 从窗口顶部到导航栏底部

 20 状态栏高度

 320 竖屏情况下的屏幕宽度

 480 320 竖屏情况下的3.5 inch 的宽度

 568 320 竖屏情况下的4.0 inch 的宽度


iPhone

iPhone 1G 320x480

iPhone 3G 320x480

iPhone 3GS 320x480

iPhone 4 640x960

iPhone 4S 640x960

iPhone 5 640x1136

iPhone 5S 640x1136

iPhone 5C 640x1136

iPhone 6 750x1334

iPhone 6 Plus 1080x1920 (开发应按照1242x2208适配)

iPhone 6S 750x1334

iPhone 6S Plus 1080x1920 (开发应按照1242x2208适配)

iPod Touch:

iPod Touch 1G 320x480

iPod Touch 2G 320x480

iPod Touch 3G 320x480

iPod Touch 4G 640x960

iPod Touch 5G 640x1136


iPad:

iPad 1 1024x768

iPad 2 1024x768

The New iPad 2048x1536

iPad mini 1024x768

iPad 4 2048x1536

iPad Air 2048x1536

iPad mini 2 2048x1536

iPad Air 2 2048x1536

iPad mini 3 2048x1536

iPad mini 4 2048x1536

iPad Pro 2732x2048


用代码编写不会触发监听的代理方法 只有手动操作才会触发代理方法


xib本质上是文件 。所以解析用initWithCoder encodeWithCode


重新计算子控件的frame 调用setNeedsDisplay 调用setNeedsLayout


不要设置自己的代理为自己

self.delegate = self;


监听控件的事件

1.delegate

2.-(voidaddTarget

3.通知


-(void)applicationDidEnterBackground:(UIAppliction *)application

{

[application beginBackgroundTaskWithExpirationHandle:^{

//后台运行的时间到期了,就会自动调用这个block

}];

/**

优先级高到低

前台运行:

后台运行:

休眠(挂起、暂停):

*/

}


plist中:Required background modes 选项 告诉系统本应用是做什么的

eg:App plays audio or streams audio/video using AirPlay 放歌曲的应用

eg:App downloads content from the network 在后台时可能下载内容


AVAudioPlayer *player = [AVAudioPlayer alloc ]initwithContentsOfURL :@“” error:@“” ];

player.numberOfLoops =  -1 ; //负数代表永久循环

[player prepareToplay];

[player play];


让定时器不因视图正在移动而暂停

NSTimer *timer = [NSTimer scheduledTimerWithTimeTnterval:2.0 target:self  selector:@selector(getUser)]  userInfo:nil repeat:YES];

[NSRunLoop mainRunLoop ]addTimer :timer  forMode: NSRunLoopCommonModes];


[self.tableView scrollToRowAtIndexPath:];         //让表格滚动到指定位置


//_created_at = Mon Jul 14 15:32:22 +0800 2014   —>NSDate —>2014-07-14 15:32:22  转化日期显示格式

NSDateFormatter *fmt =[[NSDateFormatter alloc] init];

fmt.dateFormat = @“EEE MMM dd HH:mm:ss Z yyy”;

NSDate *createDate = [fmt dateFromString :_create_at];

fmt.dateFormat = @“yyy-MM-dd HH:mm:ss”;

NSString *timeStr = [fmt stringFromDate:createDate];


//获得当前日期的年月

NSCalendar *calendar = [NSCalendar currentCalendar ];

NSDateComponents *cmps = [calendar component :NSCalendarUnitYear |NSCalendarUnitMonth fromDate:creatDate];

NSLog(@“@d @d”,cmps.year ,cmps.month);


官方应用程序图标的大小为57*57像素。icon.png

SpringBoard会自动调整较大的图像,提供方角且无光泽(不发光的图像),SpringBoard会使图像的角度变得光滑圆润,并自动添加光泽和高亮效果。

若不想使用,在Info.plist 文件中将UIPrerenderedIcon 设为true


推送类 UILocalNotification

UILocalNotificationDefaultSoundName 系统自带声音


CLLocation:封装位置信息(经纬度,海拔)

CLPlacemark:封装地表信息(位置信息CLLocation,地名name,国家country

MKUserLocation:封装地图上大头针的位置信息(位置信息CLLocation,标题title,子标题subtitle

CLLocationDegrees:度数(经度CLLocationDegrees longitude

,纬度 CLLocationDegrees latitude

CLLocationCoordinate2D:地理坐标(经度longitude,纬度latitude

MKCoordinateSpan:跨度(经度跨度,纬度跨度)

MKCoordinateRegion:区域(中心位置CLLocationCoordinate2D center,区域跨度MKCoordinateSpan



// 拦截点击事件:子空间不在有效点击区域可利用该方法拦截事件

-(UIView *)hitTest:(CGRect)point withEvent:(UIEvent *)event

{

if(CGRectContainsPoint(self.redView.frame ,point)){

return self.redView;

}

return [super hitTest:point withEvent:event];

}


other linker Flags   设置为-all_load 可以兼容c++代码



UI相关的操作只能在主线程中处理


批量删除.svn文件

sudo find /Users/apple/Desktop/版本1.1.0 -name ".svn" -exec rm -r {} \;


查询是否有残余.svn文件

$ find . -type d -name .svn


xml导入动态库后报错,尝试

1 Building Setting — Header Search Paths —  添加/usr/include/libxml2

2Building Setting — Other Linker Flags  —添加-lxml2


若再arc项目中添加非arc文件,则在Build Phases中特定非arc文件中添加-fno-objc-arc 




一个完整的由客户端发给服务端的http请求中包含以下内容:

请求行:包含了请求方法、请求资源路径、HTTP协议版本

e.g. GET /MJServer/resources/images/1.jpg HTTP/1.1


请求头:包含了对客户端的环境描述、客户端请求的主机地址等信息

e.g. Host: 192.168.1.105:8080  //主机地址

User-Agent: Mozilla/5.0 (Macintosh:Intel Mac OS X 10.9) Firefox/30.0 //客户端环境描述

Accept: text/html, */*  //客户端所能接收到的数据类型

Accept-Languagezh-cn  //客户端的语言环境


请求体:客户端发给服务器的具体数据,比如文件数据(只有post 有请求体)


URL中不能包含中文,得对中文进行转码。

urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ];


若想要发送json数据,需设置:

request.HTTPBody = json ;

[request setValue:@“application/json” forHTTPHeaderField:@“Content-Type”];


NSURLConnectionDataDelegate 数据下载


CFNetWork 此框架提供了C语言级别的网络通信能力,它将“BSD套接字BSD socket)抽象成易于使用的网络接口


默认情况下,在block中访问的外部变量是复制过去的,即写操作不对原变量生效,但可以加上__block来让其写操作生效

__block int a = 0;

void (^foo)(void) = ^{

a = 1;

}

foo();


设置应用内的系统控件语言

打开Info.plist

<key>CFBundleLocalizations</key>

<array>

<string>zh_CN</string>

<string>en</string>
</array>


对象在内存中的排布可以看成一个结构体,该结构体的大小并不能动态变化,所以无法在运行时动态的给对象增加成员变量,

而相应的,对象的方法定义都保存在类的可变区域中。objc 1.0 中,方法的定义列表是一个名为methodLists的指针的指针,所以

通过修改改指针,可以为类增加成员方法,这就是category可以增加成员方法却不能增加成员变量的原理。


objc _class 中,所有的成员变量,属性的信息说放在链表ivars中的。ivars是一个数组,

数组中的每个元素是指向Ivar(变量信息)的指针。


openssl s_client -connect www.google.com:443 </dev/null 2>/dev/null | openssl x509 -outform DER > https.cer

获得指定服务器的公开二进制证书


CFBundleDevelopmentRegion 属性 plist中指定app所使用的语言



包含运行时头文件 #import <objc/runtime.h> 


即使你实现的是自动垃圾收集的应用,也需要retainrelease创建的dispatch queue和其它dispatch对象。GCD 不支持垃圾收集模型来回收内存



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值