iOS杂技

作者: 草花凯 | 来源:发表于2017-12-05 15:16 被阅读0次

1. 这里是列表文本const(常量) extern static 等使用场景。

const NSString            * NAME_ONE = @"你好";            //全局常量,其他类中可访问 extern NSString 

static const NSString   *NAME_TWO = @"小羊";            //static 修饰 成局部变量 只能内部访问

NSString         *const WANG_NAME = @"狗";            //用此种写法代替宏(Macro)定义

在其他类文件中要想访问全局常量 :

extern NSString *NAME_ONE; 获得(NAME_ONE)

在app中可以创建一个常量类(XKConst),m文件定义各种常量

//定义常量

NSString * const CONST_NAME = @"小明";
int const SCREEN_SIZE_W = 200;

在h 文件中提供外界访问声明

UIKIT_EXTERN NSString *const CONST_NAME;
UIKIT_EXTERN int const  SCREEN_SIZE_W;

在需要用到的地方导入头文件 XKConst.h 可以直接获取SCREEN_SIZE_W 的值

2. 软件通话状态安Home健退到后台,屏幕上红色导航条显示正在通话,点击回到软件通话界面。在info.plist中设置。

<key>UIBackgroundModes</key>    
<array> 
<string>voip</string>
<string>audio</string>  
</array>

app名字

在项目中添加 InfoPlist.strings 文件,在文件中写入 CFBundleDisplayName = appName。

RGB 颜色 宏定义

#define RGB_Color(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255 blue:B/255 alpha:A]
but.BackgroundColor = RGB_Color(230,200,50,1);

navigationbar 背景颜色以及标题字体颜色

self.navigationController.navigationBar.barTintColor = RGB_Color(230,200,50,1);
[self.navigationController.navigationBar         setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

定义各种宏的规范

参照。。。。。。

统计项目中代码总行数。

终端cd 到项目目录,输入:

 find . "(" -name "*.m" -or -name "*.strings" -or -name "*.h" ")" -print | xargs wc -l  

获得某路径下的文件大小

    (1).   NSData *Fdata = [NSData dataWithContentsOfFile:fpath];
            long long   fileSize = [Fdata length];

    (2).  NSDictionary *fileAttributes = [[NSFileManager defaultManager]                                  attributesOfItemAtPath:tfpath error:NULL];
           long long  fileSize = [[fileAttributes objectForKey:NSFileSize] unsignedLongLongValue];

隐藏tableview多余的分割线

    - (void)setExtraCellLineHidden: (UITableView *)tableView{
        UIView *view =[ [UIView alloc]init];
        view.backgroundColor = [UIColor clearColor];
        [tableView setTableFooterView:view];
        [tableView setTableHeaderView:view];
    }

根据文字内容计算tableviewcell高度,在heightForRow 代理中返回即可。

- (CGFloat)sizeHeigtWithItem:(MHCommanFileInfo*)info {

    NSString *value = info.fileName;

    NSInteger width = [UIScreen mainScreen].bounds.size.width - 152;

    //获取当前文本的属性

    NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:value];

    //_text.attributedText = attrStr;

    NSRange range = NSMakeRange(0, attrStr.length);

    // 获取该段attributedString的属性字典

    NSDictionary *dic = [attrStr attributesAtIndex:0 effectiveRange:&range];

    // 计算文本的大小

    CGSize sizeToFit = [value boundingRectWithSize:CGSizeMake(width - 16.0, MAXFLOAT) // 用于计算文本绘制时占据的矩形块

                                           options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading // 文本绘制时的附加选项

                                        attributes:dic        // 文字的属性

                                           context:nil].size; // context上下文。包括一些信息,例如如何调整字间距以及缩放。该对象包含的信息将用于文本绘制。该参数可为nil

    return sizeToFit.height ;

}

tableviewcell 滑动删除或其他的系统方法

    -(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView             editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

{  
    UITableViewRowAction *rowActionSec = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault  title:@"下载"    handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
    //点击时间相关代码                                                                             
          }];

    rowActionSec.backgroundColor = [UIColor orangeColor];
    NSArray *arr = @[rowActionSec];
    return arr;
}

获取键盘高度 键盘弹出时上推界面

   S1: 注册通知

-(instancetype)init{
    if (self = [super init]) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
        [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(keyboardWasHidden:) name:UIKeyboardWillHideNotification object:nil];
    }
    return self;
}

    S2: 方法中改变Fram

- (void) keyboardWasShown:(NSNotification *) notif
{
    NSDictionary *info = [notif userInfo];
    NSValue *value = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGSize keyboardSize = [value CGRectValue].size;
    _keybordH = keyboardSize.height;

    [UIView animateWithDuration:0.3 animations:^{
        CGRect r = _botomBarV.frame;
        r.origin.y -= _keybordH;
        [_botomBarV setFrame:r];
    }];
}
- (void) keyboardWasHidden:(NSNotification *) notif
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect r = _botomBarV.frame;
        r.origin.y += _keybordH;
        [_botomBarV setFrame:r];
    }];
}

保存图片到手机相册

-(void)saveToAlbum{
UIImageWriteToSavedPhotosAlbum(_imageV.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
}
- (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    NSString *message;
    if (!error) {
        message = @"成功保存到相册";
    }else    message = [error description];
  //  NSLog(@"message is %@",message);
}

字符串的小方法

1. iOS版本字符串(4.3与4.3.2)比较
    NSString *str1 = @"6.1";
    NSString *str2 = @"6.0.3";
    if (![str1 isEqualToString:str2]) {
        if (([str1 compare:str2] != NSOrderedAscending)) {
            NSLog(@"str1 是高版本");
        }else {
            NSLog(@"str2 是高版本");
        }
    }else{
        NSLog(@"版本相等");
    }
   //NSOrderedAscending 文档解释 The left operand is smaller than the right operand.
2. 判断某个类名与字符串相同
     [NSStringFromClass([wid class]) isEqualToString:@"UIRemoteKeyboardWindow"]
3 . 根据字符串内容及属性字典计算所占  size
  NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:13.0]};    
  CGSize size = [message.contentInfo boundingRectWithSize:CGSizeMake(200, MAXFLOAT) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attributes context:nil].size;

字典倒叙排列

     NSArray *arr = [NSArray arrayWithArray:@[@"aaa",@"bbb",@"ccc"]];
     _dataArr = [[[arr reverseObjectEnumerator] allObjects] mutableCopy];

cocoaPod 使用

    cd 到项目目录下 touch  podfile  文件及
    vim podfile   i 插入  编写:

    platform :ios, '7.0'
//inhibit_all_warnings!

xcodeproj 'Demo.xcodeproj'

target :Demo1 do
  pod 'MBProgressHUD', '~> 0.9.1'
  pod 'AFNetworking', '~> 2.5.4'
  pod 'MJRefresh', '~> 2.3.2'
end
target :Demo2 do
  pod 'MBProgressHUD', '~> 0.9.1'
  pod 'AFNetworking', '~> 2.5.4'
  pod 'MJRefresh', '~> 2.3.2'
end

esc  :    wq  退出   执行 pod install

创建自己的pod库(公有私有),注意使用时podfile 文件要添加公有地址和私有地址
[地址链接](http://blog.wtlucky.com/blog/2015/02/26/create-private-podspec/)

查看当前路径文件夹下所有文件

   NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager]enumeratorAtPath:[MHAppManager instance].favoritesDirectory];
    for (NSString *fileName in enumerator){
        NSLog(@"%@",fileName);
   }

main函数 crash 代码定位

 edite shceme  --->Run -->arguments-->environment variables 
添加key values  :NSZoobieEnable    YES
breakpoint 界面调试

mysql 触发器/事务/存储过程/自定义函数/index原理/view作用

存储过程- (循环)

drop procedure if exists p_while_do;  
create procedure p_while_do()  
begin  
    declare i int;  
        set i = 1;  
        while i <= 10 do  
            /// TODO 循环存数据等。。。  
            set i = i + 1;  
        end while;  
end;  
  
call p_while_do();

相关文章

  • iOS杂技

    1. 这里是列表文本const(常量) extern static 等使用场景。 在其他类文件中要想访问全局常量 ...

  • 关于濮阳杂技产业发展的调查与建议

    (一) 濮阳是中国杂技之乡,杂技文化源远流长,杂技演艺在国内外都有重要影响...

  • 一些iOS杂技术

    这里会记录一些没用的iOS技术,但或许会是有趣的。 1.关于向前声明 为避免循环引用,C 语言有一个前向声明的机制...

  • 杂技

    心里关着一头正在歇斯底里地狂叫着的巨兽在猛烈地冲击着牢笼,哐乓,哐乓。表面上却云淡风轻,哼着小曲化着妆,即使黑眼圈...

  • 杂技

    半夜渴求一杯水时,很自然想起床头边有水可以喝,就很幸福了。慢慢的,幸福于我而言,变得越来越容易。无论我身边事物的好...

  • 杂技

    cat /etc/shells说明: 显示 /etc/shells 文件内容,即列出当前系统可用shell GNU...

  • 杂技

    杂技剧《熊猫——寻梦之旅》是我兑换的最后一场演出。它是沈阳杂技演艺集团创排的2015年度国家艺术基金项目。 用杂技...

  • (杂技)

    台前精彩十分钟, 幕后演员苦练功。 杂技走向全世界, 手捧奖杯为国荣。

  • 杂技

    杂技

  • 杂技

    晚上散步回来,见路口围了一圈人,原来是河南杂技,一个年轻的男人正在那说:各位父老乡亲,兄弟姐妹们,大家有钱的捧个钱...

网友评论

      本文标题:iOS杂技

      本文链接:https://www.haomeiwen.com/subject/qsdcixtx.html