代码块随记

无奈有时记性不好,一些经常用的随记。

九宫格

    for (int x = 0; x < 10; x++) {
    //创建按钮
    int i = x / 3;   //---- 0 1 2   行
    int j = x % 3;   //-----0 1 2   列
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.frame = CGRectMake(j * (BUTTONWIDTH + columnWidth) + columnWidth, i * (BUTTONHEIGHT + rowHeight) + rowHeight, BUTTONWIDTH, BUTTONHEIGHT);
    btn.tag = x + 1;
    [btn setTitle:[NSString stringWithFormat:@"%d",btn.tag] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
  }

裁剪图片

-(UIImage *)getImageFromImage:(UIImage*) superImage
{
    CGSize subImageSize = CGSizeMake(320, 200);
    //定义裁剪的区域相对于原图片的位置
    CGRect subImageRect = CGRectMake(0, 60, superImage.size.width, superImage.size.height);
    CGImageRef imageRef = superImage.CGImage;
    CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef, subImageRect);
    UIGraphicsBeginImageContext(subImageSize);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextDrawImage(context, subImageRect, subImageRef);
    UIImage* subImage = [UIImage imageWithCGImage:subImageRef];
    UIGraphicsEndImageContext();
    //返回裁剪的部分图像
    return subImage;
}  

//渲染缓存

self.layer.shouldRasterize=YES;
self.layer.rasterizationScale= [UIScreenmainScreen].scale;

//NSTextAttachment 调整centerY

NSTextAttachment * ment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    ment.image = [];
    ment.bounds =  CGRectMake(0, self.Label.font.descender/2.0, self.Label.font.ascender, self.Label.font.ascender);
0.jpg
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,649评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,161评论 25 709
  • 以前听过一首歌,歌名叫《越长大越孤单》。歌词的大意就如同歌名一样,一个人越长大,圈子就越来越小。 事实大家都明...
    号播阅读 2,435评论 0 0
  • 1. 月目标回顾 完成情况 本月共安排任务12 项,完成6项,完成率50%, 完成计划外任务2项 3个核心目标完成...
    yiling在路上阅读 3,003评论 2 0
  • 我们总是特别羡慕长得好看的小娃娃,在未生娃之前,我也是看到别人家的俊俏孩子总是忍不住多瞄两眼,生了娃才发现:娃的颜...
    曲鲁伟阅读 4,185评论 4 2

友情链接更多精彩内容