1.截屏
- (void)captureImageFromView:(MorphingLabel *)sender{
CGRect screenRect = [self bounds];
// UIGraphicsBeginImageContext(screenRect.size);
UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, [UIScreen mainScreen].scale);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.layer renderInContext:ctx];
UIImage *sendImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// [self.gifArr addObject:sendImage];
}
2.单元格高度适配
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
// 获取每一行需要显示的内容
NSString *text = self.dataArray[indexPath.row];
// 方法弃用。推荐使用的新方法,功能肯定是想通的,配置的参数也有类比性
// CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(300, 9999)];
NSDictionary *attributes = @{NSFontAttributeName : [UIFont systemFontOfSize:15]};
/**
* 计算字符串的绘制范围
*
* 参数1 size : 最大允许的范围
* 参数2 options : 计算多行文本,NSStringDrawingUsesLineFragmentOrigin
* 参数3 attributes : 字符串属性字典
* 参数4 context : 绘制的上下文,当前上下文 nil
*
* @return 计算后的大小
*/
CGRect rect = [text boundingRectWithSize:CGSizeMake(300, 9999) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil];
return rect.size.height + 5;
}
3.系统分享
-(void)share:(UIButton *)button {
NSMutableArray *activityItems = [[NSMutableArray alloc] init];
//可添加图片 标题 url
[activityItems addObject:getData];
// 服务类型控制器
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
}
网友评论