2015年1月20日火曜日

[iOS]iOS7で文字列のサイズを求める

//iOS6まで、非推奨
CGSize size = [textLabel.text sizeWithFont:[UIFont systemFontOfSize:fontSize]
                         constrainedToSize:textLabel.size
                             lineBreakMode:UILineBreakModeWordWrap];
//iOS7
CGSize size = [textLabel.text boundingRectWithSize:textLabel.size
                                           options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
                                        attributes:@{NSFontAttributeName:textLabel.font} context:nil].size;

2015年1月15日木曜日

[iOS]iOS7以降のModalView呼び出しと解放

float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 7.0)  {
    //iOS7以降
    //呼び出し
    [self presentViewController:vc animated:YES completion:nil];
    //解放
    [self dismissViewControllerAnimated:YES completion:nil];
} else {
    //iOS6以前
    //呼び出し
    [self presentViewController:vc animated:YES];
    //解放
    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

2015年1月14日水曜日

[iOS]iOSのバージョンを調べる

float version = [[[UIDevice currentDevice] systemVersion] floatValue];
    
if (version >= 8.0)  {
        
} else {
        
}