ios筆記(簡(jiǎn)單的天氣)

下面是一些常用的東西,但是老是忘掉,所以記錄下來,方便以后產(chǎn)查看。

一、打印出類型
- (void)viewDidLoad {
    [super viewDidLoad];
   
    NSString *test = @"測(cè)試";
   
    NSLog(@"test--%@",test);
    NSLog(@"test--地址:%p",test);
    NSLog(@"test--類名:%@",NSStringFromClass([test class]));
    NSLog(@"打印當(dāng)前函數(shù)或方法%s   打印當(dāng)前行號(hào) %d  obj=%@",__func__, __LINE__ ,test);

}
二、nil,Nil,NULL的區(qū)別

空指針:沒有指向任何東西的指針,給空指針發(fā)送消息不會(huì)報(bào)錯(cuò)。

  • nil: A null pointer to an Objiective-C object (nil是一個(gè)對(duì)象)
  • Nil: A null pointer to an Objiective-C class (nil是一個(gè)類)
  • NULL:是一個(gè)通用指針
  • NSNULL :是一個(gè)對(duì)象,用在不能使用nil的場(chǎng)合
三、判斷是否為空

接口經(jīng)常返回null,有時(shí)候又返回空字符串,有時(shí)候又返回(null),甚至<null>

1、字符串返回的格式是(null)時(shí)
if (result == nil)  
{   
    NSLog(@"空類型!");  
} 
2、返回的格式是<null>時(shí)
if ([result isEqual:[NSNull class]])  
{   
    NSLog(@"空類型!");  
}  
3、[result isEqualToString:@""]
可以一句話總結(jié)
- (BOOL)StringIsNullOrEmpty:(NSString *)str  
{  
    return (str == nil || [str isKindOfClass:[NSNull class]] || str.length == 0);  
} 
四、CocoaPods 安裝 使用

1、CocoaPods安裝和使用教程
2、CocoaPods 安裝 使用

五、UIFont 設(shè)置字體樣式

label.font = UIFont fontWithName:@"Arial-BoldItalic"
教你如何在iOS項(xiàng)目中設(shè)置各種字體
設(shè)置非系統(tǒng)內(nèi)部的字體時(shí),如果達(dá)不到想象中的效果,就用這個(gè)方法

[UIFont fontWithDescriptor:[UIFontDescriptor fontDescriptorWithName:@"BebasNeueBook" size:72] size:72]
六、字體大小適配

APP界面設(shè)計(jì)——IOS字體規(guī)范與多屏幕適配

寫了一個(gè)分類
#import "UILabel+FontAdaptation.h"

#define IS_IPHONE_6 ([[UIScreen mainScreen] bounds].size.height == 667.0f)
#define IS_IPHONE_6_PLUS ([[UIScreen mainScreen] bounds].size.height == 736.0f)

@implementation UILabel (FontAdaptation)

-(CGFloat)adjustFontSize:(CGFloat)fontsize{
    CGFloat newFont;
    if (IS_IPHONE_6){
        newFont = fontsize;
    }else if (IS_IPHONE_6_PLUS){
        newFont = fontsize*1.5;
    }else{
        newFont = fontsize;
    }
    return newFont;
}
///////////////////////////////////////實(shí)現(xiàn)文件
 UILabel *lable = [[UILabel alloc] init];
    [self.view addSubview:lable];
    lable.frame = CGRectMake(30, 100, 100, 100);
    lable.backgroundColor = [UIColor redColor];
    lable.font = [UIFont systemFontOfSize:[lable adjustFontSize:10]];
    lable.text = @"我是中國人";
六、改變tabbar字體的顏色和大小
    UIColor * color = [UIColor whiteColor];
    UIFont *font = [UIFont systemFontOfSize:50*m6Scale];
    NSMutableDictionary *dict=[NSMutableDictionary dictionary];
    [dict setObject:color forKey:NSForegroundColorAttributeName];
    [dict setObject:font forKey:NSFontAttributeName];
    self.navigationController.navigationBar.titleTextAttributes = dict;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容