- ios - 设置tabBarItem.imageInsets后,item每点一下会变小解决方案
UIEdgeInsetsMake 的top bottom left right 必须是对称的比如5,-5
exp:
vc.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0); (显示正常)
vc.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -4, 0); (每次点击 item 会变小)
- Masonry label 显示多行 设置 preferredMaxLayoutWidth
//显示多行,自适应高度
UILabel *label3 = [[UILabelalloc] initWithFrame:CGRectZero];
[self.viewaddSubview:label3];
label3.backgroundColor =[UIColorredColor];
label3.text =@"测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试!";
/* // Support for constraint-based layout (auto layout)
// If nonzero, this is used when determining -intrinsicContentSize for multiline labels
@property(nonatomic) CGFloat preferredMaxLayoutWidth NS_AVAILABLE_IOS(6_0);
*/
label3.preferredMaxLayoutWidth = (self.view.frame.size.width -10.0 * 2);
label3.numberOfLines =0;
[label3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(10.0);
make.right.mas_equalTo(-10.0);
make.top.mas_equalTo(100.0);
}];
- 获取App 相关信息接口
http://itunes.apple.com/cn/lookup?id=#appid#
注意 appid 替换成 自己App的id
- iOS webView 滑动不流畅 (改变webView 阻尼系数)
/** 改变webView 阻尼系数 */
_webView.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;
- iOS 打包的那些坑
Deployment 为 iOS 7.0 打包出来的ipa中 Assets.car 文件 大约比 Deployment 为 iOS 8.0 打包出来的ipa中 Assets.car 小一半左右 Deployment 为 iOS 9.0 打包出来的Assets.car 文件和 7.0 下差不多
- view快速添加模糊效果
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
imageView.image = [UIImage imageNamed:@"index"];
[self.view addSubview:imageView];
/** 在希望模糊的view上加一个 toolBar 即可 */
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:imageView.frame];
[imageView addSubview:toolBar];
- 对数组进行排序
#pragma mark 数组排序4-高级排序
void arraySort4() {
Student *stu1 = [Student studentWithFirstname:@"MingJie" lastname:@"Li" bookName:@"book1"];
Student *stu2 = [Student studentWithFirstname:@"LongHu" lastname:@"Huang" bookName:@"book2"];
Student *stu3 = [Student studentWithFirstname:@"LianJie" lastname:@"Li" bookName:@"book2"];
Student *stu4 = [Student studentWithFirstname:@"Jian" lastname:@"Xiao" bookName:@"book1"];
NSArray *array = [NSArray arrayWithObjects:stu1,stu2,stu3, stu4, nil nil];
// 1.先按照书名进行排序
// 这里的key写的是@property的名称
NSSortDescriptor *bookNameDesc = [NSSortDescriptor sortDescriptorWithKey:@"book.name" ascending:YES];
// 2.再按照姓进行排序
NSSortDescriptor *lastnameDesc = [NSSortDescriptor sortDescriptorWithKey:@"lastname" ascending:YES];
// 3.再按照名进行排序
NSSortDescriptor *firstnameDesc = [NSSortDescriptor sortDescriptorWithKey:@"firstname" ascending:YES];
// 按顺序添加排序描述器
NSArray *descs = [NSArray arrayWithObjects:bookNameDesc, lastnameDesc, firstnameDesc, nil nil];
NSArray *array2 = [array sortedArrayUsingDescriptors:descs];
NSLog(@"array2:%@", array2);
}
- iOS 7.0之后 UILabel展示 HTML文本方法
NSString * html = @" Some
html string hdhsd ";
NSAttributedString *attr = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
lable.attributedText = attr;
- swift单例写法
class ControversyManager {
static let sharedInstance = ControversyManager()
}
- 利用UIApplication单例拿到当前视图控制器 这样就能直接拿到当前的rootViewController。比如对它调用presentViewController: animated: completion:
就可以马上在当前状态下弹出一个视图控制器。
[[UIApplication sharedApplication].windows firstObject].rootViewController
- tableView cell 滑动时候实现 3D效果
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
///配置 CATransform3D 动画内容
CATransform3D transform ;
transform.m34 = 1.0/-800;
//定义 Cell的初始化状态
cell.layer.transform = transform;
//定义Cell 最终状态 并且提交动画
[UIView beginAnimations:@"transform" context:NULL];
[UIView setAnimationDuration:1];
cell.layer.transform = CATransform3DIdentity;
cell.frame = CGRectMake(0, cell.frame.origin.y, cell.frame.size.width, cell.frame.size.height);
[UIView commitAnimations];
}
- Label 简单图文混排
// 文字图片拼接显示
- (void)setLabel3
{
// NSTextAttachment - 附件
// 1.创建文本附件包含图片,知道附件 bounds
NSTextAttachment *attachMent = [[NSTextAttachment alloc] init];
// 设置图片
attachMent.image = [UIImage imageNamed: @"image"];
// 设置大小
CGFloat height = self.label.font.lineHeight;
attachMent.bounds = CGRectMake(0, 0, height, height);
// 添加
// 2.使用附件创建属性字符串
NSAttributedString *attrString = [NSAttributedString attributedStringWithAttachment:attachMent];
// 拼接文字
NSString *str = @"测试";
// 3.创建可变字符 拼接字符串
NSMutableAttributedString *strM = [[NSMutableAttributedString alloc] initWithString:str];
[strM appendAttributedString:attrString];
[strM appendAttributedString: [[NSAttributedString alloc] initWithString: @"测试"]];
// 设置 label 内容
self.label.backgroundColor = [UIColor grayColor];
self.label.attributedText = strM;
}
- 强制横屏 ios8 横屏状态栏不显示解决方法
:在plist文件中将 View controller-based status bar appearance 设置为NO 在application:didFinishLaunchingWithOptions:中添加下面代码
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
- UIMenuController注意事项
显示UIMenuController前必须调用becomeFirstResponder 例如 [self.view becomeFirstResponder];
必须重写canBecomeFirstResponder方法返回YES
有些控件会有系统的UIMenuItem,使用canPerformAction:withSender:方法筛选出需要的item
Tip
学习的路上总是曲折的,每个人都是从菜鸟过来的,遇到问题总是希望能够与他人沟通交流,而在各种群里问了问题就石沉大海,所以想建一个技术交流为主的群,遇到的问题可以记录下来分享给他人,方便了自己,也造就了他人,不管怎样,记录点滴,但愿与君共勉
*QQ群号:527377492 *