美文网首页
iOS之开发技巧

iOS之开发技巧

作者: Goldfish_jinyu | 来源:发表于2016-07-21 10:38 被阅读22次

    解决ImageView/Button变形

    • 保证图片在不同比例手机上不会变形的方法;
        _ImageView.contentMode = UIViewContentModeScaleAspectFill;
        _ImageView.clipsToBounds = YES;
    
        [nutritionButton setImage:[UIImage imageNamed:@"HG_Main_YYZJ"] forState:UIControlStateNormal];
        [nutritionButton.imageView setContentMode:UIViewContentModeScaleAspectFill ];
      
    

    动态高度

      CGRect rect = [@"需要展示的文字" boundingRectWithSize:CGSizeMake(SCREEN_W - (SCREEN_W/10*2.6), MAXFLOAT) 
    options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading 
    attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:14]} context:nil];
    
    

    注释:
    1.CGSizeMake(SCREEN_W - (SCREEN_W/10*2.6), MAXFLOAT)
    这段文字需要的宽高

    2.[UIFont boldSystemFontOfSize:14]
    这段文字的大小

    自动布局

    当我们设置navBar为透明时 整个屏幕坐标会向上64 ,当显示时就会出现屏幕下移 ,有人会说取动布局
    self.automaticallyAdjustsScrollViewInsets = NO; 
    
    当这个方法不好使的时候get大家一个新技能
        self.extendedLayoutIncludesOpaqueBars = YES;
    
    这个属性看单词的意思,延伸视图包含不包含不透明的Bar,是用来指定导航栏是透明的还是不透明,IOS7中默认是YES,当滚动页面的时候我们隐约能在导航栏下面看到我们页面的试图,如果设置为NO就会从导航栏下面展示我们的视图
    
    

    获取当前时间

        NSDate *now = [NSDate date];
        NSLog(@”now date is: %@”, now);
    
        NSCalendar *calendar = [NSCalendar currentCalendar];
        NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |    NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
        NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];  
      
        int year = [ dateComponent year];
        int month = [dateComponent month];
        int day = [dateComponent day];
        int hour = [dateComponent hour];
        int minute = [dateComponent minute];
        int second = [dateComponent second];
    
        NSLog(@”year is: %d”, year);
        NSLog(@”month is: %d”, month);
        NSLog(@”day is: %d”, day);
        NSLog(@”hour is: %d”, hour);
        NSLog(@”minute is: %d”, minute);
        NSLog(@”second is: %d”, second);
    

    MJ崩溃现象

    3550A584-4921-4AC4-A931-99149B057DF3.png
    MJRefresh出现崩溃现象
    
    解决办法:类库增加判断
    
    if (range.location != NSNotFound) {  
                language = [language substringToIndex:range.location];  
    }      
    
    
    get一个关于 UIslider控件方法大全

    https://my.oschina.net/u/2340880/blog/401902

    改变self.title字体颜色
    //    NSDictionary * dict=@{NSForegroundColorAttributeName :[UIColor whiteColor]};
    //    self.navigationController.navigationBar.titleTextAttributes = dict;
    
    软件下载
    http://www.orsoon.com/Mac/144664.html?winzoom=0.875
    
    状态栏
    改变状态栏颜色
    info 添加View controller-based status bar appearance字段
        [[UIApplication sharedApplication ]setStatusBarStyle:UIStatusBarStyleDefault];//黑色
        [[UIApplication sharedApplication ]setStatusBarStyle:UIStatusBarStyleLightContent];//白色
    
    状态栏详解
    http://www.cnblogs.com/ethan-qi/p/5527588.html
    
    

    http://blog.csdn.net/iukey/article/details/7327164

    单个页面需要旋转时
    #pragma mark 旋转屏幕
    - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
        
        return UIInterfaceOrientationMaskLandscape;
    }
    -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
        return UIInterfaceOrientationLandscapeRight;
    }
    - (BOOL)prefersStatusBarHidden
    {
        return NO; // 返回NO表示要显示,返回YES将hiden
    }
    
    
    iOS开发——OC篇&常用问题解答(一)

    http://www.cnblogs.com/iCocos/p/4539000.html

    富文本
    NSString * ZJYDescribeStr = @"      点击上面的注册按钮,即表示您同意《逐步环球的服务和隐私条款》";
      
      NSRange rang = {22,14};
      
      NSMutableAttributedString * att = [[NSMutableAttributedString alloc]initWithString:ZJYDescribeStr];
      NSDictionary * dic = @{NSForegroundColorAttributeName:[[UIColor purpleColor]colorWithAlphaComponent:0.3]};
      
      [att setAttributes:dic range:rang];
      
      label.attributedText = att;
    
    小技巧

    在xcode中,大家可能会想要像浏览器一样打开多个标签来查看多个文件的内容,因为之前遇到打开多个标签的情况,所以知道肯定有。可是找了半天也没有找到打开多个标签在哪里
    现在奉上快捷键:command + T

    RGB
    将一个 NSString = @“#FF0000”转换成 RGB的方法
    
    NSString *color = @“#FF0000”;
    // 转换成标准16进制数
      [color replaceCharactersInRange:[color rangeOfString:@"#" ] withString:@"0x"];
    // 十六进制字符串转成整形。           
    long colorLong = strtoul([color cStringUsingEncoding:NSUTF8StringEncoding], 0, 16);
    // 通过位与方法获取三色值
                int R = (colorLong & 0xFF0000 )>>16;
                int G = (colorLong & 0x00FF00 )>>8;
                int B =  colorLong & 0x0000FF;
               
    //string转color
    UIColor *wordColor = [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1.0];
    
    
    自定义手势收起键盘
    - (void)viewDidLoad  
    {  
        [super viewDidLoad];  
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];  
        //设置成NO表示当前控件响应后会传播到其他控件上,默认为YES。  
        tapGestureRecognizer.cancelsTouchesInView = NO;  
        //将触摸事件添加到当前view  
        [self.view addGestureRecognizer:tapGestureRecognizer];  
    }  
      
    -(void)keyboardHide:(UITapGestureRecognizer*)tap{  
        [textFiled resignFirstResponder];  
    } 
    
    设备号ID的获取
    //设备id获取
    #define DEVICE [[UIDevice currentDevice].identifierForVendor UUIDString]
    
    更改适配
    Build Active Architecture Only
    Debug  Yes
    Release  No
    
    
    滑动tableView时 收起键盘
            _tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    
    

    相关文章

      网友评论

          本文标题:iOS之开发技巧

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