美文网首页
UIBarButtonItem自定义图片

UIBarButtonItem自定义图片

作者: zxb有缘 | 来源:发表于2019-05-14 16:37 被阅读0次

    一般情况 设置背景图片 颜色会被修改
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[UIImage imageWithData:data] style:UIBarButtonItemStyleDone target:self action:nil];

    //修改图片模式后 正常了
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageWithData:data]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:nil];

    //修正图片的大小

    • (UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize
      {
      UIGraphicsBeginImageContext(CGSizeMake(reSize.width, reSize.height));
      [image drawInRect:CGRectMake(0, 0, reSize.width, reSize.height)];
      UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();

      return [reSizeImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
      }

    //最终使用
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[self reSizeImage:[UIImage imageWithData:data] toSize:CGSizeMake(40, 40)] style:UIBarButtonItemStyleDone target:self action:nil];

    相关文章

      网友评论

          本文标题:UIBarButtonItem自定义图片

          本文链接:https://www.haomeiwen.com/subject/gkceaqtx.html