ios7 UILabel sizeWithFont方法的最新寫法 ios7之後 摒棄了 sizeWithFont方法,那麼該怎麼改寫呢 不換行 CGSize fontSize = [string sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15}]; 換行的話,首先要設置 UILabel 的 numberOfLines屬性等於0,而後再計算Size NSAttributedString *name = [[NSAttributedString alloc]initWithString:string attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}]; CGRect nameRect = [name boundingRectWithSize:CGSizeMake("你想要的寬度", CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil]; CGSize nameSize = nameRect .size;