(一)随机色
<span style="font-size:14px;">[UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];</span>
(二)有时候在涉及到tableView的cell点击事件和手势事件的时候,会发现tableView的点击事件很不灵敏,只有长按松掉才有选中,对于这种情况,手势和cell的点击会发生冲突,单击手势拦截了UITableView的didSelect事件,所以会导致这样的现象
1.设置手势的delegate
2.代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
// 输出点击的view的类名
NSLog(@"%@", NSStringFromClass([touch.view class]));
// 若为UITableViewCellContentView(即点击了tableViewCell),则不截获Touch事件
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
return NO;
}
return YES;
}
(二)阻止屏幕变暗进入休眠状态
//阻止屏幕变暗,慎重使用,缺省为no 2.0
[UIApplicationsharedApplication].idleTimerDisabled =YES;
慎重使用本功能,因为非常耗电。
(三)目前,UIImage和UIView使用的是左上原点坐标,Core Image和Core Graphics使用的是左下原点坐标
(四) 打印双引号,有时候打印系统属性的时候key也有双引号
NSLog(@"%@",@"\"{打印双引号}\"");
五
<
key
>NSAppTransportSecurity</
key
>
<
dict
>
<
key
>NSAllowsArbitraryLoads</
key
>
<
true
/>
</
dict
>
六 强制弹出系统键盘
//强制使用系统键盘
- (BOOL)application:(UIApplication *)application
shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier
{
if ([extensionPointIdentifier isEqualToString:@"com.apple.keyboard-service"]) {
return NO;
}
return YES;
}
七、iOS 视频录像文件保存后删除缓存
// 保存成功后清除缓存
NSError *error;
NSFileManager *fm=[NSFileManager defaultManager];
[fm removeItemAtURL:<文件路径> error:&error];
if (error) {
NSLog(@"缓存清除失败: %@", error);
}
八、Actions added to UIAlertController must have a title -- 这个错误是因为UIAlertAction 的标题不能为空
九、一段文字设置多种文字样式
//设置不同字体颜色
-(void)fuwenbenLabel:(UILabel *)labell FontNumber:(id)font AndRange:(NSRange)range AndColor:(UIColor *)vaColor
{
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:labell.text];
//设置字号
[str addAttribute:NSFontAttributeName value:font range:range];
//设置文字颜色
[str addAttribute:NSForegroundColorAttributeName value:vaColor range:range];
labell.attributedText = str;
}
十、
XCode 7 error: “A launch storyboard or xib must be provided unless the app requires full screen” 这个警告会影响app的发布,必须的解决
解决方案:
我们勾上全屏即可:
十、
利用MJExtension处理OC里"id"关键字
id
是Objective-C里的关键字,我们一般用大写的ID
替换,但是往往服务器给我们的数据是小写的id,这个时候就可以用MJExtension框架里的方法转换一下
+ (NSDictionary *)mj_replacedKeyFromPropertyName
{
return @{@"ID": @"id"};
}
self.imgView.contentMode = UIViewContentModeScaleAspectFill;
self.imgView.clipsToBounds = YES;