p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #ffffff; min-height: 21.0px}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #ffffff}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px 'Heiti SC Light'; color: #ffffff}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #4cbf57}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px 'Heiti SC Light'; color: #4cbf57}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #e44448}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #d28f5a}p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c2349b}p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px 'Heiti SC Light'; color: #e44448}p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #8b84cf}p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px 'Heiti SC Light'; color: #d28f5a}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #8b84cf}span.s3 {font: 18.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures}span.s4 {font: 18.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #8b84cf}span.s5 {font: 18.0px Menlo; font-variant-ligatures: no-common-ligatures}span.s6 {font-variant-ligatures: no-common-ligatures; color: #c2349b}span.s7 {font: 18.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #ffffff}span.s8 {font-variant-ligatures: no-common-ligatures; color: #ffffff}span.s9 {font-variant-ligatures: no-common-ligatures; color: #e44448}span.s10 {font-variant-ligatures: no-common-ligatures; color: #4cbf57}span.s11 {font-variant-ligatures: no-common-ligatures; color: #d28f5a}span.s12 {font: 18.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #c2349b}span.s13 {font: 18.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures; color: #4cbf57}span.s14 {font: 18.0px 'Apple Color Emoji'; font-variant-ligatures: no-common-ligatures; color: #8b84cf}span.s15 {font: 18.0px 'Apple Color Emoji'; font-variant-ligatures: no-common-ligatures}span.Apple-tab-span {white-space:pre}
1.添加全局斷點,讓程序停在錯的地方 Add Exception Breakpoint
延遲多少秒調用誰的什么方法
//afterDelay 秒
//self 這個方法屬于誰
//performSelector : 方法?
[self performSelector:@selector(stand) withObject:nil afterDelay:self.imageView.animationDuration];
2.1 // 延遲0.25秒就會調用里面代碼塊的東西
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//code...
});NSBundle
//獲取到我們的APP的路徑
NSBundle *myMainBundle = [NSBundle mainBundle];
// 返回的就是一個圖片的全路徑
NSString *filePath = [myMainBundle pathForResource:iconName ofType:@"png"];使用OC數組的迭代器來遍歷
// 每取出一個元素就會調用一次block
// 每次調用block都會將當前取出的元素和元素對應的索引傳遞給我們
// obj就是當前取出的元素, idx就是當前元素對應的索引
// stop用于控制什么時候停止遍歷
[arr enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (idx == 1) {
*stop = YES;
}
NSLog(@"obj = %@, idx = %lu", obj, idx);
}];如果使用OC數組存儲對象, 可以調用OC數組的方法讓數組中所有的元素都執行指定的方法
// 注意點: 如果數組中保存的不是相同類型的數據, 并且沒有相同的方法, 那么會報錯
// [arr makeObjectsPerformSelector:@selector(say)];
// withObject: 需要傳遞給調用方法的參數
[arr makeObjectsPerformSelector:@selector(sayWithName:) withObject:@"lnj"];
該方法默認會按照升序排序
NSArray *newArr = [arr sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(Person *obj1, Person obj2) {
// 每次調用該block都會取出數組中的兩個元素給我們
// 二分
// NSLog(@"obj1 = %@, obj2 = %@", obj1, obj2);
return obj1.age > obj2.age;
// return obj1.age < obj2.age;
/
if (obj1.age > obj2.age) {
// 5 4
return NSOrderedDescending;
}else if(obj1.age < obj2.age)
{
// 4 5
return NSOrderedAscending;
}else
{
return NSOrderedSame;
}
*/
}];// 如何判斷當前是ARC還是MRC?
// 可以在編譯的時候判斷當前是否是ARC
if __has_feature(objc_arc)
NSLog(@"ARC");
else
NSLog(@"MRC");
endif
8.#if LP64 || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
else
typedef int NSInteger;
typedef unsigned int NSUInteger;
endif
- 獲取屏幕的尺寸
// CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
10.#if defined(LP64) && LP64
define CGFLOAT_TYPE double
define CGFLOAT_IS_DOUBLE 1
define CGFLOAT_MIN DBL_MIN
define CGFLOAT_MAX DBL_MAX
else
define CGFLOAT_TYPE float
define CGFLOAT_IS_DOUBLE 0
define CGFLOAT_MIN FLT_MIN
define CGFLOAT_MAX FLT_MAX
endif
/* Definition of the CGFloat' type and
CGFLOAT_DEFINED'. */
typedef CGFLOAT_TYPE CGFloat;
11-1. initWithFrame 使用代碼初始化的時候會調用,在這里一般做一些,不會調用任何方法
"用途:初始化操作(子控件)"
init 在調用init方法的時候 系統默認會調用一次initWithFrame
----------------------------使用代碼來創建會調用的的方法-----------------------
initWithCoder 當從stroyboard/xib加載就會調用這個方法,而這個方法一般是正在初始化子控件
也就是這個方法內部自控件可能是沒有值
"用途:當你需要在初始化子控件之前做一些操作的時候,可以在這個方法內部寫"
awakFromNib 只要調用完了initWithCoder之后,就直接調用awakeFromNib
當調用的時候,這個里面的子控件都是有值
"用途:在這里可以給自控件賦值(屬性)"
----------------------------通過xib/storyboard加載會調用的方法-----------------------
11-2.
+(instancetype)shopView
{
// LYSShopsView *view=[[NSBundle mainBundle] loadNibNamed:@"LYSShopsView" owner:nil options:nil].firstObject;
// NSArray *arr=[[NSBundle mainBundle] loadNibNamed:@"LYSShopsView" owner:nil options:nil];
// LYSShopsView *view=(LYSShopsView *)arr[0];
/**傳入NSBundle對象時,nil代表mainBundle
*Returns an UINib object initialized to the nib file in the specified bundle.
*拿到xib-->nib文件對象
*/
UINib *nib=[UINib nibWithNibName:@"LYSShopsView" bundle:nil];
//獲取nib文件對象內的控件數組
NSArray *arr=[nib instantiateWithOwner:nil options:nil];
LYSShopsView *view=(LYSShopsView *)arr.lastObject;
return view;
}
12.產生隨機數
u_int32_t arc4random(void);
void arc4random_addrandom(unsigned char * /dat/, int /datlen/);
void arc4random_buf(void * /buf/, size_t /nbytes/) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
void arc4random_stir(void);
u_int32_t
arc4random_uniform(u_int32_t /upper_bound/) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
ifdef BLOCKS
int atexit_b(void (^)(void)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
void *bsearch_b(const void *, const void *, size_t,
size_t, int (^)(const void *, const void *)) __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_3_2);
endif /* BLOCKS */
13.//創建一個字典(內部包含VFL語句中用到的控件)的快捷宏定義
NSDictionaryOfVariableBindings(...);
14.//創建類名字符串
NSStringFromClass(id);
15.復習簡單plist文件解析
// 1.拿到plist的文件路徑
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"cars.plist" ofType:nil];
// 2.創建對應的JSON數據
NSArray *dicts = [NSArray arrayWithContentsOfFile:filePath];
// 3.JSON->Model
NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:dicts.count];
for (NSDictionary *dict in dicts) {
// 3.1 Dict->Model
XMGCar *obj = [XMGCar carWithDict:dict];
[arrayM addObject:obj];
}
15-1. Dict->Model
+ (instancetype)carWithDict:(NSDictionary *)dict
{
XMGCar *car = [[self alloc] init];
// car.name = dict[@"name"];
// car.icon = dict[@"icon"];
// car.money = dict[@"money"];
// kvc 相當于上面3行
[car setValuesForKeysWithDictionary:dict];
return car;
}
16.KVC 可以修改ReadOnly 的key 但是按照編碼規范不可以改(可以改但不能)
17.被static修飾過的局部變量僅僅是延長生命周期,,對外還是不可見,就是說還是局部變量
18.//創建一個容納上限為18的可變數字
NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:18];
19.typedef NSUInteger NSStringEncoding;(NSString.h)
20.//輸出結果: "sss\nsss"
NSString *str1=@"sss.txt";
NSString *str= [str1 stringByDeletingPathExtension];//這個方法在NSPathUtilities.h中
NSLog(@"%@",str);//自動換行
const char *s=str.UTF8String;//返回的是靜態char*字符指針,存在靜態/常量區
printf("%s",s);
21.UITableViewController用法
設置ViewController繼承自UITableViewController
刪除storyboard中原有的控制器
拖進新控制器
設置新控制器class:ViewController
設置新控制器is initial
實現2個數據源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
22.// 懶加載
- (NSArray *)tgs
{
if (!_tgs) {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"tgs.plist" ofType:nil];
NSArray *dicts = [NSArray arrayWithContentsOfFile:filePath];
NSMutableArray *arrayM = [NSMutableArray arrayWithCapacity:dicts.count];
for (NSDictionary *dict in dicts) {
XMGTg *obj = [XMGTg tgWithDict:dict];
[arrayM addObject:obj];
}
_tgs = [arrayM copy];
}
return _tgs;
}
23.有關@property(readonly)....A....在.h中寫著對外公開但只讀,而且在.m中不能用_A賦值,只生成get方法
所以在.m中的類擴展中可以再聲明一次A @property() ...A...就可以對外只有get,對內都有
24.引入Mansonry
//define this constant if you want to use Masonry without the 'mas_' prefix
#define MAS_SHORTHAND
//define this constant if you want to enable auto-boxing for default syntax
#define MAS_SHORTHAND_GLOBALS
#import "Masonry.h"
25.NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
26.求NSString*對象的size(需要傳入UIFont字典)
#1單行
// 先計算label內文字的范圍size//
// sizeWithAttributes:內部一般傳入字體大小即可(如果label內的文字間距屬性修改過的話,還需要傳入文字間距)
CGSize nameSize = [self.status.name sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17.0]}];
#2多行
// 多行文字高度的計算,需要用到
//[self.status.text sizeWithFont:<#(UIFont *)#> constrainedToSize:<#(CGSize)#>];
#warning 求出text的bounds
[self.text boundingRectWithSize:<#(CGSize)#> options:<#(NSStringDrawingOptions)#> attributes:<#(NSDictionary *)#> context:<#(NSStringDrawingContext *)#>]
// boundingRectWithSize:CGSize文字限制范圍(一般限制寬度)
// options:枚舉NSStringDrawingUsesLineFragmentOrigin
// attributes 傳入文字屬性@{}
CGSize textMaxSize = CGSizeMake(textW, CGFLOAT_MAX);
#define TextFont [UIFont systemFontOfSize:15.0]//自己寫的宏
#CGFLOAT_MAX//系統的,前面有
CGSize temp = [self.status.text boundingRectWithSize:textMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: TextFont} context:nil].size;
27.MJExtention用法
#一般
1.// // 字典數組 -> 模型數組
// _tgs = [XMGTg objectArrayWithKeyValuesArray:dictArray];
2.// _tgs = [XMGTg objectArrayWithFile:[[NSBundle mainBundle] pathForResource:@"tgs" ofType:@"plist"]];
3.//_tgs = [XMGTg objectArrayWithFilename:@"tgs.plist"];
#復雜,模型內有模型
if (!_carGroups) {
// 說明MJCarGroup類中的cars數組,里面要存放MJCar模型
[MJCarGroup setupObjectClassInArray:^NSDictionary *{
return @{@"cars" : [MJCar class]};//return @{@"cars" : @"MJCar"};好像也可以
}];
_carGroups = [MJCarGroup objectArrayWithFilename:@"cars.plist"];
}
return _carGroups;
28.UITableView.h內部的私有NSIndexPath分類
@interface NSIndexPath (UITableView)
+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
@property(nonatomic,readonly) NSInteger section;
@property(nonatomic,readonly) NSInteger row;
@end
29.#warning WeiBaoM 是一個模型數組1??,內的對象都是id的,沒有點語法2??
// return self.WeiBaoM[indexPath.row].cellH;
return [self.WeiBaoM[indexPath.row] cellH];
30. // 5.配圖:寬高100,左邊與正文對齊,頂部距離正文距離為10
#warning 注意分情況
CGRect picture_Ima_frame = CGRectZero;
if (self.picture) {
CGFloat pictureW = 100;
CGFloat pictureH = 100;
CGFloat pictureX = textX;
CGFloat pictureY = margin + CGRectGetMaxY(text_Lab_frame);
picture_Ima_frame = CGRectMake(pictureX, pictureY, pictureW, pictureH);
}
self.picture_Ima_frame = picture_Ima_frame;
31.自定義控件在storyboard中的使用:(和系統控件是一樣的)
自定義的控件也能在storyboard中拖出使用,先拖出父控件(系統定義的),然后改名字為自定義類名即可.
自定義控件在storyboard中的使用,相當在storyboard中創建控件,調用.m.h/(或xib)方式(2中)的初始化方法(不調用整體布局方法,storyboard來布局)alloc,init/(initWithCoder,awakFromNib),只有.h.m文件但是又沒有初始化方法,也可以在storyboard中使用,(有父控件的初始化)/實現一個awakFromNib(在內修改控件內部屬性),則默認掉用了父控件的initWithCoder/nib
//在storyboard中的在dequeue..中用的,不用注冊,dequeue的第二層封裝會直接穿件storyboard中的
//(只有.h.m文件但是又沒有初始化方法,也可以在storyboard中使用,注冊無布局frame)
32.#pragma mark - 狀態欄顯示與否
//- (BOOL)prefersStatusBarHidden
//{
// return YES;
//}
33.botton有四種屬性
disable highlight normol selected
34./**當一個控件被添加到父控件中就會調用*/可用于自定義子控件等(UIView.h中的方法)&//旋轉圖片
-(void)didMoveToSuperview
{
NSLog(@"%s",__func__);
if (self.group.opened) {
self.nameView.imageView.transform = CGAffineTransformMakeRotation(M_PI_2);//旋轉圖片
#旋轉圖片 另外M_PI_2是系統宏定義在math.h中 M_PI_2 可記為 m(math).Pi.2
}else{
self.nameView.imageView.transform = CGAffineTransformMakeRotation(0);
}
}
- (void)addSubview:(UIView *)view;
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
- (void)bringSubviewToFront:(UIView *)view;
- (void)sendSubviewToBack:(UIView *)view;
- (void)didAddSubview:(UIView *)subview;
- (void)willRemoveSubview:(UIView *)subview;
- (void)willMoveToSuperview:(UIView *)newSuperview;
- (void)didMoveToSuperview;
- (void)willMoveToWindow:(UIWindow *)newWindow;
- (void)didMoveToWindow;
35.感覺各種出現的按鈕都被叫做action :
比如,向左滑動,實現commitedit..后,通過editActions ...編輯加入多少個按鈕,類環境.在editActions ...內UITableViewRowAction 設置按鈕樣式
比如;UIAlertController *提示框中的UIAlertAction *也是設置按鈕樣式
36.JSON數據就是一堆的鍵值對.一般寫在xxoo.json上
{
"size" : "98x98",//逗號間隔
"idiom" : [//value為數組
{"watch":"98x98"},
{"size": "98x98"}
],
"info" : {//value為字典
"version" : 1,
"author" : "xcode"
}
}
37.設置程序的圖標和,啟動圖片.只需要,按照一定的規矩命名圖片,并把它們放入images.x..文件夾就可以了
file:///Users/Ruojue/Movies/IOS2期/資料/day10/代碼/09-圖標和啟動圖片
38.pt(點) >= ps(像素)//不同屏幕一個點有不同的像素//點和英寸相關
imageView.frame = CGRectMake(0, 0, 100, 100);//pt(點)100x100個
像素圖片要有三張,用在不同的屏幕上
// home.png -> 100x100像素//這個現在已經不做這個圖片了,太old了
// home@2x.png -> 200x200像素
// home@3x.png -> 300x300像素
// 非retina: 100x100像素//非視網膜
// retina: 200x200像素//視網膜
// plus: 300x300像素
39.alpha// alpha<=0.01,完全透明,可以穿透,可以穿透的意思是就像不存在一樣,可以點擊里面那層的按鈕等
而且>=1,時XCode會調成半透明,用判段改成0.99就行
設置父控件的hidden=yes,其子控件也會被隱藏
設置父控件的ilpha==0.01,其子控件也會被影響 ,變得看不見
40.// 尺寸自適應:會自動計算文字大小
[label sizeToFit];
41.三.函數介紹:
NSStringFromClass:根據一個類名生成一個類名字符串
NSClassFromString: 根據一個類名字符串生成一個類名
四.思想,為什么使用NSStringFromClass NSStringFromClass:輸入類名有提示,避免輸入錯誤
42.// 1.確定重用標示:
static NSString *ID = nil;
if (ID == nil) {
ID = [NSString stringWithFormat:@"%@ID", NSStringFromClass(self)];
}
1.static NSString *str=[NSStringFromClass(self.class) stringByAppendingString:@"ID"];//會報錯,要先定義一個static,然后拿引用去賦值
2.static NSString *ID;
ID=[NSStringFromClass(self.class) stringByAppendingString:@"ID"];//不報錯
43. //設置滾動區內編劇
//這里設置完了,tableView會滾到相應偏移位置,相當于自己操作滾動,調用了那些滾動代理方法
self.tableView.contentInset=UIEdgeInsetsMake(HeadViewH+TabBarH, 0, 0, 0);
44.
#warning lable sizeToFit lable自適應字體大小
[self.lable sizeToFit];
#warning 煩了一個錯,navigationBar,應該由棧頂控制器的navigationItem屬性設置,而不是navigationController.navigationItem
//self.navigationController.navigationItem.titleView=self.lable;
self.navigationItem.titleView=self.lable;
45.
NSString *filePath =[tempPath stringByAppendingPathComponent:@"apl.plist"];
#warning 這兩句等價
NSString *filePath =[tempPath stringByAppendingString:@"/apl.plist"];
46.
#define FOUNDATION_EXPORT FOUNDATION_EXTERN
#define FOUNDATION_EXTERN extern
//系統的NSObjCRuntime.h
47.當自己的類,需要別的類的數據,或者要改別的類屬性時,在自己的類,設一個容器,存放別的類,就可以拿到別的類,實現目的,這時為了降低耦合,用代理容器,存別的類,用協議方法,實現數據交互.(非MVC中的相關類)
48.M_PI 180度 // pi
M_PI_2 90// pi/2
這是弧度2PI r(周長)
弧度 2PI 360
placeholder 占位符
49.contantoffsize內容偏移量以內容原點為原點,計算,可視范圍于內容的原點相比差值