iOS:以前笔记,未整理版。太多了,先放着吧。。。。。。。

1、**************************************************************** 单例共享 ****************************************************************

单例 共享信息

.m

 

static OneT *newone = nil;

 

+(instancetype)shalldata

{

    if (newone == nil)

    {

        newone = [[OneT alloc]init];

        newone.data_zone = [NSMutableArray array];

    }

    return newone;

}

 

调用:

OneT *one = [OneT shalldata];

OneT *two = [OneT shalldata];

 

2、**************************************************************** 日期 ****************************************************************

 

日期时间

 

//美国的时间

NSDate *date = [[NSDate alloc]init];

 

//时区

NSTimeZone *myZone = [NSTimeZone systemTimeZone];

 

 //算时差 加上时差

NSInteger interValTimer = [myZone secondsFromGMTForDate:date];

NSDate *localDate = [date dateByAddingTimeInterval:interValTimer];

NSLog(@"%@",localDate);

 

 

//明天

NSDate *date2 = [NSDate dateWithTimeIntervalSinceNow:24*60*60];

 

//昨天

NSDate *date2 = [NSDate dateWithTimeIntervalSinceNow:-ADAY];

NSLog(@"date2 = %@",date2);

 

//1970年

NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:0];

NSLog(@"%@",date2);

 

//参考日期2001年

NSDate *date3 = [NSDate dateWithTimeIntervalSinceReferenceDate:0];

NSLog(@"%@",date3);

 

 

 

//nsdate -> nsstring 类型转换

NSDate *date1 = [NSDate date];

 

1.

NSString *date1str = date1.description; //美国的时间

 

2

NSDateFormatter *dateFormat1 = [[NSDateFormatter alloc]init];

2.1

[dateFormat1 setDateFormat:@"yyyy年MM月dd日 EEEE HH mm ss zz"];

 

2.2

    [dateFormat1 setDateStyle:NSDateFormatterShortStyle];

   [dateFormat1 setTimeStyle:NSDateFormatterMediumStyle];

 

NSString *datestr2 = [dateFormat1 stringFromDate:date1];

NSLog(@"datestr2 = %@",datestr2);

 

 

 

//获取所有时区的名字

NSArray *timeZoneNames =  [NSTimeZone knownTimeZoneNames];

//新建一个时区

NSTimeZone *newZone = [NSTimeZone timeZoneWithName:@"Pacific/Fiji"];

//新建一个时间格式

NSDateFormatter *dateFormat2 = [[NSDateFormatter alloc]init];

//设置该时区

[dateFormat2 setTimeZone:newZone];

//设置时间格式

[dateFormat2 setDateFormat:@"yyyy年MM月dd日 EEEE HH:mm:ss zz"];

//打印

NSString *dateString =  [dateFormat2 stringFromDate:[NSDate date]];

NSLog(@"dateString = %@",dateString);

 

//字符串转date

NSString *dateStr4 = @"2016年07月27日 星期三 20:16:10 GMT+12";

NSDate *date4 = [dateFormat2 dateFromString:dateStr4];

NSLog(@"%@",date4);

 

 

 

3、**************************************************************** 其他 **************************************************************** 

 

 

 

NSRange newrange = NSMakeRange(1,5);

NSValue *newvalue = [NSValue valueWithRange:newrange];

NSLog(@"%@",newvalue);

NSArray *newarray = [NSArray arrayWithObjects:newvalue, nil];

NSLog(@"%@",newarray);

    

NSRange newrange2 = [newvalue rangeValue];

NSLog(@"%lu,%lu",newrange2.location,newrange2.length);

 

 

 

//封装自定义的结构体

struct MyPoint 

{

int x;

        int y;

};

struct MyPoint mypoint;

mypoint.x = 10;

mypoint.y = 100;

    

NSValue *val2 = [NSValue value:&mypoint withObjCType:@encode(struct MyPoint)];

NSLog(@"%@",val2);

    

struct MyPoint mypoint2;

[val2 getValue:&mypoint2];

NSLog(@"mypoint2.x = %d,mypoint2.y = %d",mypoint2.x,mypoint2.y);

 

 9、

@interface class_A:NSObject

@end

 

@implementation class_A

@end

 

@property int x;

@synthesize x;

 

[MyA setNumb:5]; 即使实例变量是小写,这个set后也要大写

n=[MyA numb]; 

 

[A B]  等价 A.B

 

[self 该.m文件的方法],找不到再去父类找

 

 

与文件.h.m同名

@interface class_A:NSObject

@end

 

@interface class_B:class_A

@ens

 

继承里,class_B里的方法的可以用

[self A的方法]

[self A的变量]

 

需要某文件的某些方法,可以用

@class xxx.h

 

如果xxx.h的某些方法访问不了,如init,还是要

#import xxx.h

 

重复包含的,其中一个.h可以用@class xxx(不用写.h),对应.m要#import xxx.h

 

 

同名方法优先使用class_B的方法

 

同名的方法,会自动判断[A set_value:(int)x]的类,如判断出A

 

id x;

x=任意变量、class类

 

@try

{

}

@catch

{

}

@finally

{

}

还有的@throw

存储

NSString *path = @"/Users/etcxm/test.plist";

    [dic writeToFile:path atomically:YES];

 

NSArray  *A_data_R = [NSArray array];

A_data_R = [NSArray arrayWithContentsOfFile:S_add];

 

2、

可变数组 copy 赋值给不可变数组。

 

==========================================================================

 

//编码

NSData *new_data = [s_text dataUsingEncoding:NSUTF8StringEncoding];

 

//解码

NSString *new_string = [[NSString alloc]initWithData:new_data encoding:NSUTF8StringEncoding];

 

==========================================================================

//沙盒路径

NSHomeDirectory()

 

 //工程目录

[NSBundle mainBundle]

==========================================================================

 


    NSArray *data = [NSArray arrayWithObjects:@"zhang3",@"li4", nil];

    

    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"ceshi83.txt"];

    

    BOOL status = [NSKeyedArchiver archiveRootObject:data toFile:path];

    

    NSLog(@"%@",status?@"成功":@"失败");

    

    NSArray *r_data = [NSKeyedUnarchiver unarchiveObjectWithFile:path];

    

    NSLog(@"%@",r_data);

 

 

 6、

instancetype:返回与初始化类相同的类型。

 

-(instancetype)initWith…

{

self=[super init];

if(self)

{

}

return self;

}

 

-(class_A *)initwithone:(int)a other:(int)b

{

self=[super init];

if(self)

{

[self seta:a b:b ] ;

}

return self;

}

 

 

 

+(instancetype)robotWithName:(NSString*)r_name andage:(int)r_age

{

#if 0

    return [[self alloc]initWithName:(NSString*)r_name andage:(int)r_age];

#else

    

    Robot *new_R = [[Robot alloc]initWithName:r_name andage:r_age];

    return new_R;

#endif

}

 ==========================================================================

标签

- (void)createImageLabel
{
    float gap = 15;
    float gap2 = 15;
    float hangWidth = 0;
    NSMutableArray <NSMutableArray*> *dataSource_section = [NSMutableArray arrayWithCapacity:0];
    NSMutableArray<imageLabelHandle*> *dataSource_item = [NSMutableArray arrayWithCapacity:0];
    
    hangWidth = gap + gap;
    NSLog(@"int-%lf",hangWidth);
    for (int i = 0; i< imageLabelArray.count; i++) {
        imageLabelHandle *handle = imageLabelArray[i];
        CGFloat tag_width = handle.label_width;//[ToolManager getWidthWithText:handle.t_label_name font:[UIFont systemFontOfSize:13]];
        NSLog(@"curr-%lf",tag_width);
        
        if (hangWidth + tag_width > App_Frame_Width) {
            hangWidth = gap + gap + tag_width + gap2;
            [dataSource_section addObject:dataSource_item];
            dataSource_item = [NSMutableArray arrayWithCapacity:0];
            [dataSource_item addObject:imageLabelArray[i]];
//            NSLog(@"yiman-%lf",hangWidth);
        }else{
            hangWidth += tag_width + gap2;
//            NSLog(@"wei-%lf",hangWidth);
            [dataSource_item addObject:imageLabelArray[i]];
        }
    }
    if ( [dataSource_section.lastObject isEqualToArray:dataSource_item] == NO ) {
        [dataSource_section addObject:dataSource_item];
    }
    
//    float width = 70;
    float height = 30;
    float x = 0;//(SCREEN_WIDTH - 280)/5.;
    float y = 50;
//    float blank = (SCREEN_WIDTH -280)/5.;
    for (int i= 0; i< dataSource_section.count; i++) {
        x = gap;
        y = 50 + i * (height + 10);
        
        CGFloat tempWidth = 0;
        for (imageLabelHandle *handle in dataSource_section[i]) {
            tempWidth += handle.label_width;
        }
        gap2 = (App_Frame_Width - tempWidth - gap - gap)/([dataSource_section[i] count]-1);
        
        for (int j= 0; j< [dataSource_section[i] count]; j++) {
            
            imageLabelHandle *handle = dataSource_section[i][j];

            UIButton *imageLButton = [YLBasicView createButton:IColor(38, 38, 38)
                                                          text:handle.t_label_name
                                                     backColor:IColor(220, 220, 220)
                                                       cordius:3.
                                                          font:[UIFont systemFontOfSize:13]];
            imageLButton.frame = CGRectMake(x,
                                            y,
                                            handle.label_width,
                                            height);
            imageLButton.titleLabel.textAlignment = NSTextAlignmentCenter;
            imageLButton.tag = j;
            [imageLButton addTarget:self action:@selector(imageButtonBeClicked:) forControlEvents:UIControlEventTouchUpInside];
            [whiteView addSubview:imageLButton];
            x += handle.label_width + gap2;
        }
    }
    allHeight = y + height + 20;
    whiteView.frame = CGRectMake(0,
                                 SCREEN_HEIGHT,
                                 SCREEN_WIDTH,
                                 allHeight
                                 );
}

 

posted on 2016-12-13 11:03  leonlincq  阅读(416)  评论(0编辑  收藏  举报