iOS小結(jié)
- 1靠闭、相應(yīng)點擊指定view區(qū)域
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
NSSet *allTouches = [event allTouches]; //返回與當(dāng)前接收者有關(guān)的所有的觸摸對象
UITouch *touch = [allTouches anyObject]; //視圖中的所有對象
CGPoint point = [touch locationInView:self.view]; //返回觸摸點在視圖中的當(dāng)前坐標(biāo)
int x = point.x;
int y = point.y;
NSLog(@"touch (x, y) is (%d, %d)", x, y);
}
- 2惜论、修改UITextField的默認顏色文字大小
修改默認顏色
self.textField.placeholder = placeholder;
[self.textField setValue:[UIColor colorwithHexString:@"cccccc"] forKeyPath:@"_placeholderLabel.textColor"];
[self.textField setValue:[UIFont boldSystemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];
- 3槽卫、去掉字符串的空格
NSString *str = @" sdsdijls ijdlsj sdffsd;kl fs;dkf;s";
//去掉開頭和結(jié)尾的空格
NSString *str1 = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
//替換的方法 。去掉所有空格
NSString *str2 = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
str1 = @"sdsdijls ijdlsj sdffsd;kl fs;dkf;s";
str2 = @"sdsdijlsijdlsjsdffsd;klfs;dkf;s";
- 4扒袖、修改UITextField文字貼在邊框的
// 默認情況下,當(dāng)向textField輸入文字時,文字會緊貼在textField左邊框上.我們可以通過設(shè)置textField的leftView,設(shè)置一個只有寬度的leftView.這樣還不夠,因為默認leftView是不顯示的.還需要將leftViewMode設(shè)置為UITextFieldViewModeAlways.這樣就完成了.
//設(shè)置文本框左邊的view
UITextField *textField = [[UITextField alloc]init];
textField.frame = CGRectMake(10, 30, 300, 30);
[self.view addSubview:textField];
textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 8, 0)];
//設(shè)置顯示模式為永遠顯示(默認不顯示)
textField.leftViewMode = UITextFieldViewModeAlways;
- 5塞茅、取數(shù)組中n個元素
取數(shù)組中n個元素
NSArray *array = @[@"品牌",@"顏色",@"上牌時間",@"行駛里程",@"描述"];
NSArray * array1 = [array objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 3)]];
NSLog(@"array1==%@",array1);
- 6、在UITableView上添加tap手勢可用的方法:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCounts)];
tap.cancelsTouchesInView = false;
[tableView addGestureRecognizer:tap];
- 7僚稿、UITableviewCell上的控件在點擊cell時候背景顏色消失的解決方案:
lable.layer.backgroundColor=[UIColor redColor].CGColor;
- 8凡桥、打包上傳app時候報錯和對應(yīng)的解決方法
1蟀伸、ERROR ITMS-90049: “This bundle is invalid. The bundle identifier contains disallowed characters. [See the section of the Application Programming Guide entitled The Application Bundle.]”
解決方案:找到第三方庫中得info.plist文件添加bundle id 蚀同,修改bundle version ,bundle version string
具體解決步驟:在xcode左下角搜索框搜索info.plist啊掏,搜索出所有info.plist文件對這三個key缺少的添加蠢络,不對的修改
2、
ERROR ITMS-90530: “Invalid MinimumOSVersion. Apps that only support 64-bit devices must specify a deployment target of 8.0 or later. MinimumOSVersion in ‘dqcclient.app’ is ‘7.0’.”
解決方案:編譯時拔掉真機迟蜜,否者編譯會針對真機的系統(tǒng)架構(gòu)進行編譯
3刹孔、
ERROR ITMS-90535: “Unexpected CFBundleExecutable Key. The bundle at ‘dqcclient.app/TencentOpenApi_IOS_Bundle.bundle’ does not contain a bundle executable. If this bundle intentionally does not contain an executable, consider removing the CFBundleExecutable key from its Info.plist and using a CFBundlePackageType of BNDL. If this bundle is part of a third-party framework, consider contacting the developer of the framework for an update to address this issue.”
解決方案:在xcode左下角搜索框搜索info.plist,搜索出所有info.plist文件娜睛,刪除掉第三方info.plist文件中的Executable file 字段
4髓霞、
ERROR ITMS-90529: “Invalid package. Applications built with sdk 9.0 or later must be packaged as proper IPA files.”
解決方案:現(xiàn)在上傳需是IPA文件
具體解決步驟:將xcode編譯的.app文件放入Payload文件夾內(nèi),壓縮成.zip文件畦戒,修改其后綴為.ipa文件方库,即可。
- 9障斋、UITableViewCell 上的imageView 用SDWebimage 加載圖片時候 出現(xiàn)內(nèi)存暴漲的現(xiàn)象:
1.同時加載圖片過多纵潦;
2.加載的圖片過大;
- 10垃环、添加延時方法 和取消延時的方法
[self performSelector:@selector(hidden) withObject:self afterDelay:3];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hidden) object:nil];//取消對應(yīng)的方法
[NSObject cancelPreviousPerformRequestsWithTarget:self];//取消全部邀层。
[[self class] cancelPreviousPerformRequestsWithTarget:self];//取消全部。
- 11遂庄、判斷數(shù)組中存在某個元素
NSArray *array = @[@"品牌",@"顏色",@"上牌時間",@"行駛里程",@"描述"];
//判斷數(shù)組中存在某個元素
if ([array indexOfObject:@"品牌"]!= NSNotFound) {
NSLog(@"存在");
}
- 12寥院、xib上拖ScrollView 添加約束后再加label、button等導(dǎo)致scrollView無法滑動
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
self.scrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
[self.scrollView setContentSize:CGSizeMake(kScreenWidth, 1000)];
}
- 13涛目、數(shù)學(xué)公式
NSLog(@"%i",abs(-3));
NSLog(@"%d",abs(-4));
//floor() 向下取整
NSLog(@"%f",floorf(-3.1415926));
NSLog(@"%d",(int)floorf(-3.1415926));
// ceil()向上取整
NSLog(@"%f",ceilf(3.14));
NSLog(@"%d",(int)ceilf(3.14));
//round() 四舍五入
NSLog(@"round()%f",roundf(3.14));
NSLog(@"round()%d",(int)roundf(3.14));
NSLog(@"round()%f",roundf(3.74));
//fmax()求兩個數(shù)的最大值
NSLog(@"fmax()%f",fmaxf(3.14, 2.71));
NSLog(@"fmax()%d",(int)fmaxf(3.14, 2.71));
//------------------- 可以嵌套
NSLog(@"fmax()%f",fmaxf(20.69, fmaxf(3.14, 19.87)));
//fmin()求兩個數(shù)的最小值
NSLog(@"fmin%f",fmin(14, 12));
NSLog(@"fminf()%d",(int)fminf(3.14, 3.141));
//fmod()求兩個數(shù)整除后的余數(shù)
NSLog(@"fmodf%f",fmodf(5.00, 3.00));
//modf()/modff()/modfl() 浮點數(shù)分解為整數(shù)和小數(shù)
float a;
float c;
float b = 8.22;
a = modff(b, &c);
NSLog(@"modf()-整數(shù)部分-%f",c);
NSLog(@"modf()-小數(shù)部分-%f",a);
打印結(jié)果:
打印結(jié)果:
2015-08-13 14:09:55.520 Micro Shop[15342:164204] 3
2015-08-13 14:09:55.564 Micro Shop[15342:164204] 4
2015-08-13 14:09:55.565 Micro Shop[15342:164204] -4.000000
2015-08-13 14:09:55.565 Micro Shop[15342:164204] -4
2015-08-13 14:09:55.565 Micro Shop[15342:164204] 4.000000
2015-08-13 14:09:55.565 Micro Shop[15342:164204] 4
2015-08-13 14:09:55.565 Micro Shop[15342:164204] round()3.000000
2015-08-13 14:09:55.565 Micro Shop[15342:164204] round()3
2015-08-13 14:09:55.565 Micro Shop[15342:164204] round()4.000000
2015-08-13 14:09:55.566 Micro Shop[15342:164204] fmax()3.140000
2015-08-13 14:09:55.566 Micro Shop[15342:164204] fmax()3
2015-08-13 14:09:55.566 Micro Shop[15342:164204] fmax()20.690001
2015-08-13 14:09:55.566 Micro Shop[15342:164204] fmin12.000000
2015-08-13 14:09:55.566 Micro Shop[15342:164204] fminf()3
2015-08-13 14:09:55.566 Micro Shop[15342:164204] fmodf2.000000
2015-08-13 14:09:55.566 Micro Shop[15342:164204] modf()-整數(shù)部分-8.000000
2015-08-13 14:09:55.567 Micro Shop[15342:164204] modf()-小數(shù)部分-0.220000
- 14秸谢、label增加留白(重寫 - (CGSize)intrinsicContentSize)
- (CGSize)intrinsicContentSize {
CGSize originalSize = [super intrinsicContentSize];CGSize size = CGSizeMake(originalSize.width+20, originalSiz
e.height+20);return size;
}
如果是用代碼約束经磅,如果你只想設(shè)置坐標(biāo)不想設(shè)置大小,那么你需要像上面的代碼一樣钮追,在- (CGSize)intrinsicContentSize為你的label指定一個默認大小
如果是在Xib里预厌,那么你需要在下面這個Instrinsic Size的屬性里設(shè)置為placeholder,這樣元媚,Xcode就不會報錯了