- ios - 設(shè)置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 顯示多行 設(shè)置 preferredMaxLayoutWidth
//顯示多行尺锚,自適應(yīng)高度
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 相關(guān)信息接口
http://itunes.apple.com/cn/lookup?id=#appid#
注意 appid 替換成 自己App的id
- iOS webView 滑動不流暢 (改變webView 阻尼系數(shù))
/** 改變webView 阻尼系數(shù) */
_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];
- 對數(shù)組進行排序
#pragma mark 數(shù)組排序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 = @"<html><body><style>body{background-color:#FFFFFF;color:#555555;}img {max-width:200px;max-height:200px;}</style> <p><img src=http://tp.mnks.cn/tp_105.jpg></p>Some<input type='text' size='5'> <br/>html <strong>string</strong> <b>hdhs</b><i>d</i> </body></html>";
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。比如對它調(diào)用presentViewController: animated: completion:
就可以馬上在當前狀態(tài)下彈出一個視圖控制器问欠。
[[UIApplication sharedApplication].windows firstObject].rootViewController
- tableView cell 滑動時候?qū)崿F(xiàn) 3D效果
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
///配置 CATransform3D 動畫內(nèi)容
CATransform3D transform ;
transform.m34 = 1.0/-800;
//定義 Cell的初始化狀態(tài)
cell.layer.transform = transform;
//定義Cell 最終狀態(tài) 并且提交動畫
[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.創(chuàng)建文本附件包含圖片肝匆,知道附件 bounds
NSTextAttachment *attachMent = [[NSTextAttachment alloc] init];
// 設(shè)置圖片
attachMent.image = [UIImage imageNamed: @"image"];
// 設(shè)置大小
CGFloat height = self.label.font.lineHeight;
attachMent.bounds = CGRectMake(0, 0, height, height);
// 添加
// 2.使用附件創(chuàng)建屬性字符串
NSAttributedString *attrString = [NSAttributedString attributedStringWithAttachment:attachMent];
// 拼接文字
NSString *str = @"測試";
// 3.創(chuàng)建可變字符 拼接字符串
NSMutableAttributedString *strM = [[NSMutableAttributedString alloc] initWithString:str];
[strM appendAttributedString:attrString];
[strM appendAttributedString: [[NSAttributedString alloc] initWithString: @"測試"]];
// 設(shè)置 label 內(nèi)容
self.label.backgroundColor = [UIColor grayColor];
self.label.attributedText = strM;
}
- 強制橫屏 ios8 橫屏狀態(tài)欄不顯示解決方法
:在plist文件中將 View controller-based status bar appearance 設(shè)置為NO 在application:didFinishLaunchingWithOptions:中添加下面代碼
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
- UIMenuController注意事項
顯示UIMenuController前必須調(diào)用becomeFirstResponder 例如 [self.view becomeFirstResponder];
必須重寫canBecomeFirstResponder方法返回YES
有些控件會有系統(tǒng)的UIMenuItem,使用canPerformAction:withSender:方法篩選出需要的item
Tip
學(xué)習(xí)的路上總是曲折的顺献,每個人都是從菜鳥過來的旗国,遇到問題總是希望能夠與他人溝通交流,而在各種群里問了問題就石沉大海注整,所以想建一個技術(shù)交流為主的群能曾,遇到的問題可以記錄下來分享給他人度硝,方便了自己,也造就了他人寿冕,不管怎樣蕊程,記錄點滴,但愿與君共勉
*QQ群號:527377492 *