zoukankan      html  css  js  c++  java
  • iOS-常用代码片段

    • 常用宏
    // 屏幕尺寸
    #define kMainScreenSize [UIScreen mainScreen].bounds.size
    // 屏幕宽度
    #define kMainScreenWidth kMainScreenSize.width
    // 屏幕高度
    #define kMainScreenHeight kMainScreenSize.height
    // iOS7
    #define IOS_7 ([UIDevice currentDevice].systemVersion.doubleValue < 8.0)
    // AppDelegate
    #define kAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)
    // RGB颜色
    #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
    #define RGB(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
    // 去除字符串前后空格
    #define trim(str) ([str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]])
    // KeyPath自动提示宏
    #define KEY_PATH(obj,keyPath) @(((void)obj.keyPath,#keyPath))
    
    • 等比例缩放
    CGSize scaledSize(CGSize originSize,CGFloat maxW,CGFloat maxH){
        CGSize size = CGSizeZero;
        if (originSize.width > originSize.height) {
            // 大于最大宽度
            if (originSize.width > maxW) {
                size.width = maxW;
                size.height = maxW / originSize.width * originSize.height;
            }
            else{
                size = originSize;
            }
        }
        else{
            // 大于最大高度
            if (originSize.height > maxH) {
                size.height = maxH;
                size.width = maxH /originSize.height * originSize.width;
            }
            else{
                size = originSize;
            }
        }
        return size;
    }
    
  • 相关阅读:
    zoj 3279 线段树 OR 树状数组
    fzu 1962 树状数组 OR 线段树
    hdu 5057 块状链表
    hdu3487 Play with Chain
    bzoj 1588营业额统计(HNOI 2002)
    poj2823 Sliding Window
    poj2828 Buy Tickets
    poj2395 Out of Hay
    poj3667 Hotel
    poj1703 Lost Cows
  • 原文地址:https://www.cnblogs.com/lancely/p/5782722.html
Copyright © 2011-2022 走看看