iphone - 在 UIToolbar 上镜像局部图像

标签 iphone ios objective-c

我正在尝试制作类似这样的东西:

enter image description here

我不确定如何像这个人在 tom 和 bottom 工具栏上所做的那样半透明地镜像图像。

我将专辑封面保存在 UIImage 中....我可以只选择它的顶部并在顶部工具栏上翻转它并在底部工具栏上翻转底部吗?请记住,我需要在两个单独的工具栏上使用它,这些可以在 UIToolbar 上完成吗?我如何获得半透明的外观?

最佳答案

这些只是 UIImageViews 沿 x 轴翻转,并在其上绘制了渐变。 看看代码示例。您可能需要改变颜色并调整框架、开始和停止颜色...

#import <QuartzCore/CAGradientLayer.h>
#import <QuartzCore/CALayer.h>

UIImageView *imgView = [[UIImageView alloc] initWithImage: coverImage];
//flip the view
imgView.transform = CGAffineTransformScale(self.imgView.transform, 1, -1);
CGRect frame = imgView.frame;
frame.size.height = 50.0; //or any other value
imgView.frame = frame;
self.imgView.contentMode = UIViewContentModeBottom;
self.imgView.layer.masksToBounds = YES;
//set the gradient
CAGradientLayer *layer = [CAGradientLayer layer];
layer.frame = self.imgView.bounds;
UIColor *startCol = [UIColor colorWithRed: 1.0 green: 1.0 blue: 1.0 alpha: 0.5];
UIColor *endCol = [UIColor colorWithRed: 1.0 green: 1.0 blue: 1.0 alpha: 1];
layer.colors = [NSArray arrayWithObjects: (id)startCol.CGColor, (id)endCol.CGColor, nil];
layer.startPoint = CGPointMake(0.5, 0);
layer.endPoint = CGPointMake(0.5, 1);
[self.imgView.layer addSublayer: layer];

关于iphone - 在 UIToolbar 上镜像局部图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18495348/

相关文章:

ios - 如何使标签栏图标图像变小?

iphone - 缩放、裁剪和剪切视频 iPhone

ios - 如果服务器有受信任的证书,需要哪些步骤才能使用 NSURLConnection 在 IOS 上点击该链接?

Objective-c 代码等于守卫

objective-c - 包装 NSUserDefaults 的模式是什么?

iphone - 通过ios发送附件到salesforce native rest sdk

iphone - 在 App Purchase 中不适用于 iPhone 5 设备

ios - 如何在 SceneKit 中使用 OBJ 文件或 CTM 文件而不是 DAE 文件?

ios - 选择等于 0 时禁用右栏按钮

iphone - 数据库在 Sqlite 中被锁定