1.UITableView****點擊段頭收齊放下咧织、****cell****側(cè)滑刪除****Demo —> /****Work / text1Demo**
2.****改變****UITextField****的****placeholder字體的顏色
{
textField.placeholder = @"username is in here!";
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placehold'];
}
3.lable里的字體設(shè)置不同顏色和字體大小
{
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String扼劈,try your best to test attributed string text"];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor blueColor]
range:NSMakeRange(0,5)];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:NSMakeRange(6,12)];
[str addAttribute:NSForegroundColorAttributeName
value:[UIColor greenColor]
range:NSMakeRange(19,6)];
[str addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"Arial" size:30.0]
range:NSMakeRange(0, 5)];
[str addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"Arial" size:30.0]
range:NSMakeRange(6, 12)];
[str addAttribute:NSFontAttributeName
value:[UIFont fontWithName:@"Arial" size:30.0]
range:NSMakeRange(19, 6)];
UILabel *attrLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 150, 320 - 40, 90)];
attrLabel.attributedText = str;
attrLabel.numberOfLines = 0;
}
iOS UIFont字體名字大全(http://blog.sina.com.cn/s/blog_6c9d5da50101fujl.html)
4. Masonry的使用(http://www.cocoachina.com/ios/20141219/10702.html)**)
Masonry支持哪一些屬性
@property (nonatomic, strong, readonly) MASConstraint *left;
@property (nonatomic, strong, readonly) MASConstraint *top;
@property (nonatomic, strong, readonly) MASConstraint *right;
@property (nonatomic, strong, readonly) MASConstraint *bottom;
@property (nonatomic, strong, readonly) MASConstraint *leading;
@property (nonatomic, strong, readonly) MASConstraint *trailing;
@property (nonatomic, strong, readonly) MASConstraint *width;
@property (nonatomic, strong, readonly) MASConstraint *height;
@property (nonatomic, strong, readonly) MASConstraint *centerX;
@property (nonatomic, strong, readonly) MASConstraint *centerY;
@property (nonatomic, strong, readonly) MASConstraint *baseline;
這些屬性與NSLayoutAttrubute的對照表如下
其中l(wèi)eading與left trailing與right在正常情況下是等價的但是當(dāng)一些布局是從右至左時(比如阿拉伯文?沒有類似的經(jīng)驗)則會對調(diào)換句話說就是基本可以不理不用用left和right就好了
在Masonry中能夠添加autolayout約束有三個函數(shù)
- (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
- (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block;
- (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;
mas_makeConstraints只負(fù)責(zé)新增約束Autolayout不能同時存在兩條針對于同一對象的約束否則會報錯
mas_updateConstraints針對上面的情況會更新在block中出現(xiàn)的約束不會導(dǎo)致出現(xiàn)兩個相同約束的情況
mas_remakeConstraints則會清除之前的所有約束僅保留最新的約束
三種函數(shù)善加利用就可以應(yīng)對各種情況了
5.iOS****調(diào)用系統(tǒng)功能****http://www.reibang.com/p/78db0e46d954
6.****去掉****UItableview headerview黏性
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == _tableView) {
CGFloat sectionHeaderHeight = 36;
if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
}
說明
sectionHeaderHeight的值要根據(jù)自己的而定
_tableView如果一個類里有多個表格缘挑,要明確指明要去掉哪一個表格頭的粘性
7.iOS****完整****App資源收集
http://www.henishuo.com/ios-app-fully-code/
8.****獲取文件大小****fileSize &&文件刪除
NSDictionary *fileAttributes = [[NSFileManager defaultManager] fileAttributesAtPath:path traverseLink:YES];
unsigned long long length = [fileAttributes fileSize];
float ff = length/1024.0/1024.0;
NSLog(@"length== %.2f",ff);
---------------------
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
//如果存在就刪除
[[NSFileManager defaultManager] removeItemAtPath: path error:nil];
}
9.獲取本機(jī)當(dāng)前語言
/** *得到本機(jī)現(xiàn)在用的語言* en:英文zh-Hans:簡體中文zh-Hant:繁體中文ja:日本...... */
+ (NSString*)getPreferredLanguage {
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString* preferredLang = [languages objectAtIndex:0];
NSLog(@"Preferred Language:%@", preferredLang);
**return **preferredLang;
}
10.圖片拉伸
//加載圖片
UIImage *image = [UIImage imageNamed:@"chat_send_nor"];
//設(shè)置端蓋的值
CGFloat top = image.size.height * 0.5;
CGFloat left = image.size.width * 0.5;
CGFloat bottom = image.size.height * 0.5;
CGFloat right = image.size.width * 0.5;
//設(shè)置端蓋的值
UIEdgeInsets edgeInsets = UIEdgeInsetsMake(top, left, bottom, right);
//設(shè)置拉伸的模式
UIImageResizingMode mode = UIImageResizingModeStretch;
//拉伸圖片
UIImage *newImage = [image resizableImageWithCapInsets:edgeInsets resizingMode:mode];
//設(shè)置按鈕的背景圖片
[btn setBackgroundImage:newImage forState:UIControlStateNormal];
####11.UIAlertView****的字體大小和顏色自定義**
- (IBAction)showBigAlert:(id)sender {
UIAlertView* find = [[UIAlertView alloc] initWithTitle:@"big size view" message:@"do you see it" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
//[find setDelegate:self];
/*
UIAlertView *find = [[UIAlertView alloc] initWithFrame:CGRectMake(5, 20, 320,700)];
find.title=@"big size view" ;
find.message=@"some message";
*/
[find show];
[find release];
}
//- (void)willPresentAlertView:(UIAlertView *)alertView
-(void)willPresentAlertView:(UIAlertView *)alertView {
[alertView setFrame:CGRectMake(1, 20, 1000, 600)];
for( UIView * view in alertView.subviews )
{
if( [view isKindOfClass:[UILabel class]] )
{
UILabel* label = (UILabel*) view;
label.textAlignment = UITextAlignmentLeft;
label.font=[UIFont fontWithName:@"STHeitiSC-Medium" size:18];
label.textColor=[UIColor greenColor];
}
if ( [view isKindOfClass:[UIButton class]] ){
}
12.UITextField中輸入文字或英文返回文本長度
- (void)textFieldDidBeginEditing:(UITextField *)textField{
[textField addTarget:self action:@selector(textFieldEditChanged:) forControlEvents:UIControlEventEditingChanged];
}
- (void)textFieldEditChanged:(UITextField *)textField{
if (textField.text.length == 0) {
[_sendButton setTitleColor:LIGHTGAYCOLOR forState:(UIControlStateNormal)];
_sendButton.userInteractionEnabled = NO;
}else{
[_sendButton setTitleColor:SUBJECTCOLOR forState:(UIControlStateNormal)];
_sendButton.userInteractionEnabled = YES;
}
}
13.JSON的 “” 轉(zhuǎn)換為 nil
使用AFNetworking時盛撑,使用
AFJSONResponseSerializer *response = [[AFJSONResponseSerializer alloc] init];
response.removesKeysWithNullValues = YES;
_sharedClient.responseSerializer = response;
這個參數(shù)removesKeysWithNullValues可以將null的值刪除,那么就Value為nil了
14.忽略靜音開關(guān)
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
15.iOS中幾種定時器
CADisplayLink
1)創(chuàng)建方法
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(handleDisplayLink:)];
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
2)停止方法
[self.displayLink invalidate];
self.displayLink = nil;
當(dāng)把CADisplayLink對象add到runloop中后藻雪,selector就能被周期性調(diào)用仰坦,類似于重復(fù)的NSTimer被啟動了扣孟;執(zhí)行invalidate操作時,CADisplayLink對象就會從runloop中移除瞬雹,selector調(diào)用也隨即停止昧谊,類似于NSTimer的invalidate方法。
3)特性
屏幕刷新時調(diào)用
CADisplayLink是一個能讓我們以和屏幕刷新率同步的頻率將特定的內(nèi)容畫到屏幕上的定時器類酗捌。CADisplayLink以特定模式注冊到runloop后呢诬,每當(dāng)屏幕顯示內(nèi)容刷新結(jié)束的時候,runloop就會向CADisplayLink指定的target發(fā)送一次指定的selector消息胖缤,CADisplayLink類對應(yīng)的selector就會被調(diào)用一次尚镰。所以通常情況下,按照iOS設(shè)備屏幕的刷新率60次/秒